react-use-state-async
A custom hook trigger call async function each dependencies changes. Support holding and updating for fetch data.
Demo
Install
With npm
npm install --save react-use-state-async
With yarn
yarn add react-use-state-async
Usage
;; ;
Props
useStateAsync(
callback: () => any | async () => Promise<any>,
dependencies: Array<any>
)
Exposed
parameter | type | description |
---|---|---|
isLoading | boolean | `true` if the callback function is running |
data | any | the data is returned in callback function |
error | any | the error is thrown in callback function |
setData | function | update `data` state |
fetch | function | trigger call callback function |