@sjblurton/use-axios-get
v0.1.4
Published
useAxiosGet gets data form a rest API, stores it in the cache, error handles, and passes a status for loading, error, and successful fetching.
Downloads
3
Maintainers
Readme
useAxiosGet
useAxiosGet gets data form a rest API, stores it in the cache, error handles, and passes a status for loading, error, and successful fetching.
install
npm i @sjblurton/use-axios-get
yarn add @sjblurton/use-axios-get
Import useArray
import useAxiosGet from "@sjblurton/use-axios-get";
To call the hook...
const {status, data, error, mutate} = useAxiosGet<Data>(
Possible Use Sanarios
function App() {
const {status, data: todos, error, mutate} = useAxiosGet<MockData>(
"https://jsonplaceholder.typicode.com/todos"
);
if (status === "idle") return <div>idling...</div>;
if (status === "pending") return <div>loading...</div>;
if (status === "error") return <div>{error?.message}</div>;
return (
<div className="App">
{todos?.map((todo) => (
<h2>{todo.title}</h2>
))}
<button onClick={mutate}>Mutate</button>
</div>
);
}
Links
GitHub: https://github.com/sjblurton/use-axios-get NPM: https://www.npmjs.com/package/@sjblurton/use-axios-get