What Happens Without Cleanup
You'll learn: The real consequences when you skip cleanup in useEffect — and why they're more than just theoretical problems.
The Cost of Missing Cleanup
When you forget to return a cleanup function from useEffect, your side effects keep running even after they should have stopped. This isn't just bad practice — it creates concrete, observable bugs in your application.
Four Common Problems
1. Memory Leaks
Event listeners and subscriptions pile up with each re-render. If your component renders 50 times, you now have 50 active listeners consuming memory. Your app gradually slows down.
2. Duplicate Listeners
Without cleanup, every re-run of your effect adds another event listener. Click a button once, and three handlers fire. Scroll the window, and five scroll handlers trigger. Your app becomes unpredictable.
3. Stale Closures
Old effect runs capture old prop/state values. When those stale listeners finally fire, they reference outdated data. A "delete item" button might delete the wrong item because it remembers an old ID.
4. Updates to Unmounted Components
An async operation completes after the component unmounts. Calling setState on an unmounted component triggers React warnings and can cause crashes. Your console fills with "Can't perform a React state update on an unmounted component" errors.
The Domino Effect
These problems compound. A leaked timer keeps firing. Each fire triggers a state update. Each update causes a re-render. Each re-render adds another leaked timer. Your once-snappy app grinds to a halt.
Key Takeaway: Skipping cleanup doesn't just violate best practices — it creates memory leaks, duplicate behavior, stale data bugs, and crashes. Always clean up event listeners, timers, subscriptions, and async operations.