@weichwarenprojekt/react-async-effect
v0.1.0
Published
Wrapper around useEffect that allows to run async operations in an effect, eliminating the sideffects
Downloads
2
Keywords
Readme
react-async-effect
react-async-effect
is a custom React hook that helps you handle side effects in a React component, with improvements for async effects.
Quickstart
- 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 }, []);