1.0.0 • Published 3 years ago
@jeswr/use-async-effect v1.0.0
useAsyncEffect
Convenience function for usage of useEffect with async functions in React.
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.
1.0.0
3 years ago