1.0.0 • Published 12 months ago

react-custom-fetch v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
12 months ago

react-custom-fetch

a custom React hook to Fetch Data

Install

npm install --save react-custom-fetch

Usage

To use the UseFetch hook, you can import it into your React component and call it with a string argument that has your api endpoint for which you want to get the response of data. The hook will default have a dummy json fetched data for testing if you don't pass anything. You can use isLoading to handle loading and errorStatus to check the api request.

import { UseFetch } from "react-custom-fetch";

const App = () => {
  const { data, isLoading, errorStatus } = UseFetch("");
  if (isLoading) {
    return <>loading..........</>;
  }
  return (
    <div className="App">
      {data?.products?.map((s) => (
          <img src={s?.images?.[0]} alt="" />
      ))}
      test
    </div>
  );
};

export default App;
1.0.0

12 months ago