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.
- Host: GitHub
- URL: https://github.com/honzabrecka/usesafeeffect
- Owner: honzabrecka
- License: mit
- Created: 2020-03-04T23:09:25.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-03-05T11:28:48.000Z (over 5 years ago)
- Last Synced: 2025-02-18T06:36:44.324Z (8 months ago)
- Topics: hooks, hooks-api-react, race-condition-prevention, react, useeffect
- Language: JavaScript
- Homepage:
- Size: 71.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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]
)
```