An open API service indexing awesome lists of open source software.

https://github.com/honzabrecka/usesafeeffect

A hook designed to perform an async effect in a safe way, thus prevent possible and undesired race condition.
https://github.com/honzabrecka/usesafeeffect

hooks hooks-api-react race-condition-prevention react useeffect

Last synced: 7 months ago
JSON representation

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

Awesome Lists containing this project

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]
)
```