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

1.0.0 • Public • Published

useAsyncEffect

Convenience function for usage of useEffect with async functions in React.

GitHub license npm version build Dependabot semantic-release

Why

Convenience and makes code cleaner. The following is allowed

import { useAsyncEffect } from "@jeswr/use-async-effect";

function MyComponent() {
  useAsyncEffect(async () => {
    /* Effect goes here */
  }, []);
  return /* JSX Output */
}

in constrast, async function calls with useEffect in React should be structured as follows:

import { useEffect } from "react";

function MyComponent() {
  useEffect(() => {
    (async () => {
      /* Effect goes here */
    })();
  }, []);
  return /* JSX Output */
}

License

©2021–present Jesse Wright, MIT License.

Readme

Keywords

Package Sidebar

Install

npm i @jeswr/use-async-effect

Weekly Downloads

6

Version

1.0.0

License

MIT

Unpacked Size

5.28 kB

Total Files

5

Last publish

Collaborators

  • jeswr