Asynchronous methods within hooks can lead to issues, where your asynchronous code resolves after your component / hook was unmounted.
This usually causes react warnings, that you cannot set state on an unmounted component.
const MyComponent = ({ id }) => {
const [status, setStatus] = useState();
const [data, setData] = useState();
useMountedEffect(async (isMounted) => {
setStatus("LOADIGN");
try {
const data = await fetchMyData({ id });
// only set state if we are still mounted
if (isMounted()) {
setData(data);
setStatus("DONE")
}
} catch (e) {
if (isMounted()) {
setStatus("ERROR")
}
}
}, [id])
}