Understanding React’s useEffect cleanup function - LogRocket Blog

PHOTO EMBED

Fri Jan 13 2023 14:24:40 GMT+0000 (Coordinated Universal Time)

Saved by @EMR4HKLMN

>useEffect(() => {
    const controller = new AbortController();
    const signal = controller.signal;

        fetch(API, {
            signal: signal
        })
        .then((response) => response.json())
        .then((response) => {
            // handle success
        });
    return () => {
        // cancel the request before component unmounts
        controller.abort();
    };
}, []);
content_copyCOPY

https://blog.logrocket.com/understanding-react-useeffect-cleanup-function/