react-custom-fetch
v1.0.0
Published
use this useFetch hook and simply pass your api endpoint you will get your api response.
Downloads
1
Readme
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;