# @jeswr/use-async-effect

> Convenience function for usage of useEffect with async functions in React

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

## Install

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

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2021-02-19 |
| First published | 2021-02-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 5.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Jesse Wright |
| Maintainers | jeswr |
| Keywords | React, useEffect, async |

## Links

- npm: https://www.npmjs.com/package/@jeswr/use-async-effect
- Repository: https://github.com/jeswr/useAsyncEffect
- Homepage: https://github.com/jeswr/useAsyncEffect#readme
- Issues: https://github.com/jeswr/useAsyncEffect/issues
- npm.io page: https://npm.io/package/@jeswr/use-async-effect

## Dependencies (1)

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

## Recent versions

- 1.0.0 (latest) — 2021-02-19

## README

# useAsyncEffect

Convenience function for usage of useEffect with async functions in React.

[![GitHub license](https://img.shields.io/github/license/jeswr/useAsyncEffect.svg)](https://github.com/jeswr/useState/blob/master/LICENSE)
[![npm version](https://img.shields.io/npm/v/@jeswr/use-async-effect.svg)](https://www.npmjs.com/package/@jeswr/use-async-effect)
[![build](https://img.shields.io/github/workflow/status/jeswr/useAsyncEffect/Node.js%20CI)](https://github.com/jeswr/useAsyncEffect/tree/main/)
[![Dependabot](https://badgen.net/badge/Dependabot/enabled/green?icon=dependabot)](https://dependabot.com/)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)

## Why

Convenience and makes code cleaner. The following is allowed

```ts
import { useAsyncEffect } from "@jeswr/use-async-effect";

function MyComponent() {
  useAsyncEffect(async () => {
    /* Effect goes here */
  }, []);
  return /* JSX Output */
}
```

in constrast, async function calls with useEffect in React should be structured as follows:

```ts
import { useEffect } from "react";

function MyComponent() {
  useEffect(() => {
    (async () => {
      /* Effect goes here */
    })();
  }, []);
  return /* JSX Output */
}
```

## License

©2021–present
[Jesse Wright](https://github.com/jeswr),
[MIT License](https://github.com/jeswr/useAsyncEffect/blob/master/LICENSE).

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