React API Hooks

React hooks to interact with an API from a stateless component using axios.

npm i react-api-hooks -s
reacthooksAPIaxiosstateless

Reference

useAPI(url, config) ⇒ useAPIOutput

React hook used to make a an API call using axios.

Allows you to pass an axios config object, for complete control of the request being sent.

Kind: global function
Returns: useAPIOutput - output

ParamTypeDefaultDescription
urlstringURL that the API call is made to.
configObject{}Axios config object passed to the axios.request method.

useAPIOutput : Object

The object returned by the useAPI hook.

Kind: global typedef
Properties

NameTypeDescription
dataObject | undefinedThe data attribute from the axios response.
responseObject | undefinedThe axios response.
errorObject | undefinedThe axios error object is an error occurs.
isLoadingbooleanIndicates if their is a pending API call.
setDatasetDataFuncSet the response data object.

setDataFunc : function

setData property of useAPIOutput

Kind: global typedef

ParamTypeDescription
newDataArray.<Object>New data array that overwrites current data.