DEV Community

Discussion on: The useEffect hook in ReactJS

Collapse
 
themubashir919 profile image
Muhammad Mobashir

You forgot another important use-case that is the 'return use case'.
You can use return to execute code that will be executed every time the component is about to destroyed.

This is most useful if you have created an event listener in useEffect and want it to be destroyed before the component is rerendered or else multiple event listeners might be created.