use-safe-effect-hook

1.0.0 • Public • Published

useSafeEffect

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

Installation

yarn add use-safe-effect-hook

Usage

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

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.00latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.00

Package Sidebar

Install

npm i use-safe-effect-hook

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

3.06 kB

Total Files

5

Last publish

Collaborators

  • honzabrecka