Chapter 10 · Example 5 · Closures in React

Escaping the closure trap

An effect refreshes ref.current every render while a stable empty useCallback calls it, giving onClick the latest state without breaking memoization.

Loading live editor…