Stale Closures in Hooks
Understand why hooks can capture outdated values in their closures and the common ways to avoid or intentionally leverage this.
A 'stale closure' happens when a function created during one render — like an effect callback, an event handler, or a setTimeout callback — captures a prop or state value from that specific render, and that captured value becomes outdated ('stale') by the time the function actually executes, because a newer render has since produced a fresher value the closure doesn't see.
A stale closure is like a photograph of the whiteboard taken at the start of a meeting — if you refer back to that photo later assuming it reflects everything currently written on the board, you'll miss every edit that happened since the picture was snapped.