# react-async-handler

> React hook for handling asynchronous task

Latest version **1.0.0** (published 2021-02-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-async-handler
pnpm add react-async-handler
yarn add react-async-handler
bun add react-async-handler
```

## 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 | 2021-02-28 |
| First published | 2021-02-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 8.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | mnindrazaka@gmail.com |
| Maintainers | mnindrazaka |

## Links

- npm: https://www.npmjs.com/package/react-async-handler
- Repository: https://github.com/mnindrazaka/react-async-handler
- Homepage: https://github.com/mnindrazaka/react-async-handler#readme
- Issues: https://github.com/mnindrazaka/react-async-handler/issues
- npm.io page: https://npm.io/package/react-async-handler

## Dependencies (3)

- [react](https://npm.io/package/react.md) ^17.0.1
- [react-dom](https://npm.io/package/react-dom.md) ^17.0.1
- [typescript](https://npm.io/package/typescript.md) ^4.2.2

## Recent versions

- 1.0.0 (latest) — 2021-02-28

## README

# react-async-handler
React hook for handling asynchronous task

## Install

```bash
npm install react-async-handler
```

## Usage

```javascript
import useAsyncHandler from 'react-async-handler'

const [execute, { status, data, error }] = useAsyncHandler(() => fetch('https://jsonplaceholder.typicode.com/todos'))
```

## API

### Return type

#### execute

type `(...args: any[]) => Promise<any>`

This is the function to execute the async function

#### status

type `string`

The status of the async process, the value can be `idle` `loading` `success` or `error`

#### data

type `any`

The data that returned from the `Promise`

#### error

type `Error`

The error object that caught from `Promise`

### Parameters

#### callback

type `(...args: any[]) => Promise<any>`

This is the function that return a `Promise` that you want to execute

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