arrow_backBACK TO DRILLS
Blue Belt - MediumuseeffectPREMIUM
Passing an async Function Directly to useEffect
A developer wants an effect to fetch data and clean up an in-flight request on unmount.
//REACT_MODULE
useEffect(async () => {
const controller = new AbortController();
const data = await fetchData({ signal: controller.signal });
setData(data);
return () => controller.abort();
}, []);Why does the cleanup function returned from this effect never actually run?