@-ft/use-async-state
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

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>;
}

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.1.0
    2
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.1.0
    2

Package Sidebar

Install

npm i @-ft/use-async-state

Weekly Downloads

2

Version

0.1.0

License

MIT

Unpacked Size

1.29 kB

Total Files

4

Last publish

Collaborators

  • mjy9088