🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

@etheryte/react-hooks

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@etheryte/react-hooks

Common React hooks for worry-free state and control flow management.

2.0.2
Source
npm
Version published
Weekly downloads
731
37.41%
Maintainers
1
Weekly downloads
 
Created
Source

@etheryte/react-hooks

Common React hooks for worry-free state and control flow management.

Installation

yarn add @etheryte/react-hooks

Hooks

useUpdateEffect(effect, dependencies?)

Same as useEffect, but only when the dependencies change, not on the first render.
useEffect fires on the first render and then whenever dependencies change, useUpdateEffect fires only when the dependencies change.

useAsyncEffect(asyncEffect, dependencies?)

useEffect with async helpers. The effect is passed a function isStale which returns a boolean value indicating whether the dependencies have changed between the start of the async effect and the moment you call it.

useAsyncEffect(async (isStale) => {
  const result = await longAsyncRequest();
  // If the dependencies changed between the request start and now, discard the result
  if (isStale()) {
    return;
  }
  setFoo(result);
}, dependencies);

useAsyncUpdateEffect(asyncEffect, dependencies?)

Combines useUpdateEffect and useAsyncEffect.

useAsyncState(getter, dependencies?)

A state variable similar to useState that fetches its value from an async source whenever the dependencies change. Stale values are handled automatically.

const value = useAsyncState(async () => {
  if (condition) {
    return undefined;
  }
  return longAsyncRequest();
}, dependencies);

Keywords

react

FAQs

Package last updated on 27 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts