useApi
The useAPI
hook is used for invoking API calls and manage the response data accordingly. You should call onApi
function to fetch and load the data.
Example Usage:
const fetchData = () => {
return fetch('<API URL>');
};
const { data, error, isLoading, onApi } = useApi(fetchData);
Hook Argument
apiFunction
apiFunction
Type |
---|
Function of type: () => Promise (Required) |
Hook Return Value
data
data
Type | Default |
---|---|
unknown (generic) | null |
error
error
Type | Default |
---|---|
String | Empty String |
isLoading
isLoading
Type | Default |
---|---|
boolean | false |
onApi
onApi
Type |
---|
Function of type: () => Promise |
Updated 12 months ago
What’s Next