Catalog npm
PACKAGE EXPLORERView in registry

@-ft/use-unmounted

npm

React useUnmounted hook

Versions collected1
Direct dependencies2From release 0.1.0
Last observed20 Oct, 21:49 UTC

README

Current package documentation

use-unmounted - react useUnmounted hook

do async operations in useEffect, and set state safety

Usage

import { useUnmounted } from '@-ft/use-unmounted';

function MyComponent() {
  const unmountedPersist = useUnmounted();
  const [state, setState] = useState("Loading...");
  useEffect(() => {
    (async () => {
      const result = await fetchSomething();
      if (unmountedPersist.current) {
        // if the component is unmounted, setState is not safe
        return;
      }
      setState(result);
    })();
  }, [unmountedPersist, setState]);
  return <div>{state}</div>;
}

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 1

Collected releases
VersionPublishedDirect dependenciesOpen version
0.1.0Registry latest22 Sept 20232

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Repository

PENDING
42ts/-ft-use-unmounted

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 21:49 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:f83f6ac4b357a74b16074e9e2a60aba93467d722d6a12965466c09d159500d5a