DEV Community

Discussion on: Get Up And Running With The useEffect Hook.

Collapse
 
gass profile image
Gass • Edited

It's an easy way of explaining and understanding how useEffect works. But I agree. Maybe it would be better to create an example using something like window dimensions which from my point of view requires the useEffect hook. Needed for adding and removing the event listener.

useWindowDimensions custom hook

From React docs

The clean-up function runs before the component is removed from the UI to prevent memory leaks. Additionally, if a component renders multiple times (as they typically do), the previous effect is cleaned up before executing the next effect.