use-async-effekt
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

useAsyncEffekt

Example

import { useAsyncEffect, isMounted, unwrap } from "use-async-effekt";

const App = () => {
  const [user, setUser] = useState<null | User>(null);

  useAsyncEffect(async resolve => {
    const user = await resolve(loadUser());
    if (isMounted(user)) {
      setUser(unwrap(user));
    }
  }, []);

  if (user === null) {
    return <>LOADING</>;
  }

  return <>{user.displayName}</>;
};

Installation

# npm
npm i use-async-effekt

# yarn
yarn add use-async-effekt

Package Sidebar

Install

npm i use-async-effekt

Weekly Downloads

1

Version

1.0.6

License

MIT

Unpacked Size

3.66 kB

Total Files

9

Last publish

Collaborators

  • danuel