# @sullivan/use-async

> Perform async operations within react

Latest version **1.0.0** (published 2020-05-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install @sullivan/use-async
pnpm add @sullivan/use-async
yarn add @sullivan/use-async
bun add @sullivan/use-async
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2020-05-14 |
| First published | 2019-07-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Chris Sullivan |
| Maintainers | icarus-sullivan |
| Keywords | react, use, async, dynamic, useAync |

## Links

- npm: https://www.npmjs.com/package/@sullivan/use-async
- Repository: https://github.com/icarus-sullivan/react-use-async
- Homepage: https://github.com/icarus-sullivan/react-use-async#readme
- Issues: https://github.com/icarus-sullivan/react-use-async/issues
- npm.io page: https://npm.io/package/@sullivan/use-async

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2020-05-14
- 0.1.0 — 2019-08-19
- 0.0.4 — 2019-07-04
- 0.0.3 — 2019-07-04
- 0.0.2 — 2019-07-04
- 0.0.1 — 2019-07-04

## README

![npm version](https://img.shields.io/npm/v/@sullivan/use-async.svg) ![npm license](https://img.shields.io/npm/l/@sullivan/use-async.svg)

# @sullivan/use-async
Hook friendly asynchronous operations for React 16.8+. 

## Installation
```
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 (
    <div onClick={() => dispatch('some_url')}>
      <h1>{loading ? 'Loading' : 'Done'}</h1>
    </div>
  );
};
```

### Options

`useAsync(fn, options?) => Response`

| Option | Description | Type |
|--|--|--|
| debounce | Milliseconds to perform a debounce, ignores if unset | number |
| memoize | If memoization should be done | boolean |


### Response

| 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 | 



----

## Changelog 
**0.2.0**

- Removed withAsync HOC
- Added options for debounce and memoization

---
_Source: https://npm.io/package/@sullivan/use-async · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
