# use-safe-effect-hook

> A hook designed to perform an async effect in a safe way, thus prevent possible and undesired race condition.

Latest version **1.0.0** (published 2020-03-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install use-safe-effect-hook
pnpm add use-safe-effect-hook
yarn add use-safe-effect-hook
bun add use-safe-effect-hook
```

## 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-03-04 |
| First published | 2020-03-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | jan.brecka@gmail.com |
| Maintainers | honzabrecka |

## Links

- npm: https://www.npmjs.com/package/use-safe-effect-hook
- Repository: https://github.com/honzabrecka/useSafeEffect
- Homepage: https://github.com/honzabrecka/useSafeEffect#readme
- Issues: https://github.com/honzabrecka/useSafeEffect/issues
- npm.io page: https://npm.io/package/use-safe-effect-hook

## Dependencies (1)

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

## Recent versions

- 1.0.0 (latest) — 2020-03-04

## README

# useSafeEffect

A hook designed to perform an async effect in a safe way, thus prevent possible and undesired race condition.

## Installation

```console
yarn add use-safe-effect-hook
```

## Usage

```js
useSafeEffect(
  ({ checkEffectValidity, handleEffectError }) => {
    anAsyncAction(id)
      .then(checkEffectValidity)
      // state is updated only if effect is still valid
      .then(updateState)
      // error is shown only if effect is still valid
      .catch(handleEffectError(showError))
  },
  [id]
)
```

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