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

Type

Function of type: () => Promise<unknown> (Required)

Hook Return Value

data

Type

Default

unknown (generic)

null

error

Type

Default

String

Empty String

isLoading

Type

Default

boolean

false

onApi

Type

Function of type: () => Promise<unknown>


What’s Next