In this case you can introduce a variable to track if the component is unmounted or not. If you use functional component, you can write something like this: useEffect(() => { let isMounted = true; // track whether component is mounted
request.get(url) .then(result => { if (isMounted) { setState(result); } }); return () => { // clean up isMounted = false; };
}, []); // only on "didMount"
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
In this case you can introduce a variable to track if the component is unmounted or not. If you use functional component, you can write something like this:
useEffect(() => {
let isMounted = true; // track whether component is mounted
}, []); // only on "didMount"