Chapter 10 · Example 4 · Closures in React

Stale closures in Refs

A callback stored in useRef captures props and state only once at mount, so updating ref.current inside an effect keeps the closure current.

Loading live editor…