2.0.4 • Published 9 months ago

@etheryte/react-hooks v2.0.4

Weekly downloads
-
License
-
Repository
github
Last release
9 months ago

@etheryte/react-hooks

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

Installation

yarn add @etheryte/react-hooks

Hooks

useUpdateEffect(effect, dependencies?)

Use effect on every update except the initial render. Accepts the same parameters as React.useEffect().

useAsyncEffect(asyncEffect, dependencies?)

React.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?)

Use async effect on every update except the initial render. Accepts the same parameters as useAsyncEffect(). 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.

useAsyncState(getter, dependencies?)

A state variable like React.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);
2.0.3

9 months ago

2.0.2

9 months ago

2.0.4

9 months ago

2.0.1

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.1

2 years ago