DEV Community

Discussion on: Using refs to check if a component is still mounted.

Collapse
 
tusharkashyap63 profile image
Tushar Kashyap

See if you are able to cancel the request/promise in the clean up function of useEffect and check if it was cancelled before updating the state, that is basically the gist of the official React blog in the age of hooks.

"An optimal solution would be to find places where setState() might be called after a component has unmounted, and fix them."

This article does that exactly.

Any place you feel cancelling the process or request is not an option or too much work you can definitely use this, just a tool in your arsenal.