0.1.0 • Published 8 months ago

@-ft/use-async-state v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

use-async-state - react useAsyncState hook

do async operations in useEffect, and set state safety

Usage

import { useAsyncState } from '@-ft/use-async-state';

function MyComponent() {
  const [state, setState] = useAsyncState("Loading...");
  useEffect(() => {
    // setState is safe even if the component is unmounted
    (async () => setState(await fetchSomething()))();
  }, [setState]);
  return <div>{state}</div>;
}
0.1.0

8 months ago