React API Hooks

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

npm i react-api-hooks -s
reacthooksAPIaxiosstateless

Reference

useParams(initialParams, debounceWait) ⇒ useParamsOutput

React hook to keep query parameters in state.

Used in conjunction with the other hooks to filter and pagination API calls.

Includes the ability the debounce an update, which is useful for delaying API calls while the user is typing.

Kind: global function
Returns: useParamsOutput - output

ParamTypeDefaultDescription
initialParamsObjectThe initial parameters to keep in states
debounceWaitnumber500The time to debounce the params update when calling debouncedUpdateParams

useParamsOutput : Object

The object returned by the useParams hook.

Kind: global typedef
Properties

NameTypeDescription
paramsObjectThe current params to be used when making an API call.
isStalebooleanIs their a debounced params update waiting to timeout. (Are we waiting for the user to stop typing)
setParamssetParamsFuncFunction used to set new parameters
updateParamsupdateParamsFuncFunction used to update current parameters
debouncedSetParamssetParamsFuncDebounced call made to setParams
debouncedUpdateParamsupdateParamsFuncDebounced call made to updateParams

setParamsFunc : function

setParams property of useParamsOutput

Kind: global typedef

ParamTypeDescription
newParamsObjectNew params object that overwrites the current params.

updateParamsFunc : function

updateParams property of useParamsOutput

Kind: global typedef

ParamTypeDescription
paramsUpdateObjectPartial update to be merged with current params.