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

Type
Function of type: () => Promise (Required)

Hook Return Value

data

TypeDefault
unknown (generic)null

error

TypeDefault
StringEmpty String

isLoading

TypeDefault
booleanfalse

onApi

Type
Function of type: () => Promise

What’s Next