use-api-call-hook
v1.0.2
Published
Custom hook for making API calls with loading state
Downloads
2
Readme
use-api-call
Custom hook for making API calls with loading state.
Installation
You can install the package via npm:
npm install use-api-call
yarn add use-api-call
Examples
import React from 'react';
import useApiCall from 'use-api-call';
const YourComponent = () => {
const { loading, error, data, makeApiCall } = useApiCall(yourApiFunction);
const handleButtonClick = () => {
makeApiCall(/* your API request parameters */);
};
return (
<div>
<button onClick={handleButtonClick} disabled={loading}>
{loading ? 'Loading...' : 'Make API Call'}
</button>
{error && <div>Error: {error.message}</div>}
{data && <div>Data: {JSON.stringify(data)}</div>}
</div>
);
};
export default YourComponent;