@sjblurton/use-axios-get
TypeScript icon, indicating that this package has built-in type declarations

0.1.4 • Public • Published

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

Package Sidebar

Install

npm i @sjblurton/use-axios-get

Weekly Downloads

0

Version

0.1.4

License

MIT

Unpacked Size

15 kB

Total Files

21

Last publish

Collaborators

  • sjblurton