Scenario-Based · Section 23
Scenarios: Effects & Stale Closures
7 questions. Debugging scenarios around useEffect dependencies, cleanup, stale closures, timers, listeners and connections.
Most real React bugs come from effects: infinite loops, stale values in timers, requests that outlive the page and connections that never close. These scenarios walk through the root cause of each, the fix, and how to prove it is gone.
01Your API is called infinitely. What could be wrong?02A timer keeps using an old state value. Why?03An event listener always logs outdated data. Why?04You navigate away from a page, but an API request still updates state. How would you fix it?05A WebSocket connection remains active after leaving the page. What should you do?06Your effect depends on an object that changes every render. How do you solve it?07Why does adding a function to the dependency array cause repeated execution?