@kornil92/react-fetch-hook
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

React fetch hook

Examples can be found in the example folder.

How to use

  • Install the package

npm i @kornil92/react-fetch-hook

  • Use it
import React from "react";
import useFetch from "@kornil92/react-fetch-hook";

const App = () => {
  const { status, data, error } = useFetch<{ file: string }>("https://aws.random.cat/meow");

  if (status === "error") {
    return <div>Error: {error.message}</div>;
  } else if (status === "success") {
    return (
      <div>
        <img src={data.file} width={600} />
      </div>
    );
  } else {
    return <div>Loading</div>;
  }
};

Readme

Keywords

Package Sidebar

Install

npm i @kornil92/react-fetch-hook

Weekly Downloads

0

Version

1.0.2

License

ISC

Unpacked Size

3.47 kB

Total Files

4

Last publish

Collaborators

  • kornil92