A simple customizable react hook for handling API in your react project.
Javascript , React JS , Node js
- Handle API Responce
- Handle API Loading
- Handle API error
Create vite + React or simple react app
npx create-react-app project_nameOr
npm create vite@latestUse this on any component or App.jsx file if you want.
const [loading, error, response] = useApi(
"http://localhost:3000/api/products/name"
);
if (error) {
return <h1>Something went wrong!</h1>;
}
if (loading) {
return <h1>Loading...</h1>;
}Just pass your api on the useApi hook and useApi hook will give your 3 response that are
- loading - it will check if api is ready or not
- error - it will throw an error if API dosen't respond
- response - it will show the result/response of API
we can also handle all the responses and can customize the useApi for our own usecase scenario.
For support, Just Star ⭐ the Repo and enjoy learnig the most usefull customizable react hook😎😎
