react-async-effect
is a custom React hook that helps you handle side effects in a React component, with improvements for async effects.
- Install the package using the following command:
npm install --save @weichwarenprojekt/react-async-effect
- Import the useAsyncEffect hook in your component file:
import { useAsyncEffect } from '@weichwarenprojekt/react-async-effect';
- Use the hook in your component, e.g. for fetching data from an api:
useAsyncEffect(async () => { const response = await fetch('https://api.example.com/data'); const data = await response.json(); // Do something with data }, []);