Perform async operations within react
npm install @sullivan/use-async
npm install --save @sullivan/use-async
`
or
`
yarn add @sullivan/use-async
`
Usage
`javascript
import React from 'react';
import { useAsync } from '@sullivan/use-async';const Example = (props) => {
const { loading, data, error, dispatch } = useAsync(fetch);
return (
dispatch('some_url')}>
{loading ? 'Loading' : 'Done'}
);
};
`$3
useAsync(fn, options?) => Response`| Option | Description | Type |
|--|--|--|
| debounce | Milliseconds to perform a debounce, ignores if unset | number |
| memoize | If memoization should be done | boolean |
| Field | Description |
|--|--|
| loading | If the async call is occuring |
| error | Any error that was thrown |
| data | The success result of the async call |
| dispatch | How to invoke the async function |
----
- Removed withAsync HOC
- Added options for debounce and memoization