stale closure
A function that still sees old values because it was created during an earlier render and never replaced.
In more detail
An Effect or listener with an empty dependency array keeps the props and state of its first render forever. Include the values in the dependency array, use an updater function, or read the latest handler from a ref.
Related terms
- closure — A function bundled with the variables it remembers from the scope where it was created.
- dependency array — The array of values given to hooks such as useEffect, useMemo and useCallback that tells React when to re-run them.
- listener churn — Removing and re-adding the same event listener on every render because the handler function is new each time.
Taught in
- State with useState: Immutability And Asynchronous Batching — React 19 & Modern Component Architecture
- Keys In Depth: Identity Preservation And Identity Resetting — React 19 & Modern Component Architecture
- Creating Event Listener Hooks with Clean Teardown Logic — React 19 & Modern Component Architecture
- React.memo, useMemo, And useCallback: Optimization Costs — React 19 & Modern Component Architecture
- The React Compiler: Automated Memoization Under The Hood — React 19 & Modern Component Architecture