JSPM

@jeswr/use-async-effect

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q33374F
  • License MIT

Convenience function for usage of useEffect with async functions in React

Package Exports

  • @jeswr/use-async-effect

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@jeswr/use-async-effect) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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.