listener churn
Removing and re-adding the same event listener on every render because the handler function is new each time.
In more detail
It wastes work and can miss events in between. Storing the latest handler in a ref and subscribing once, re-subscribing only when the event type or target changes, avoids both churn and stale closures.
Related terms
- event listener — A function registered with addEventListener that the browser calls whenever a given event happens on an element or on window.
- stale closure — A function that still sees old values because it was created during an earlier render and never replaced.
- ref — A React handle that points at a real DOM element, so code can focus it, measure it or attach listeners.
Taught in
- Creating Event Listener Hooks with Clean Teardown Logic — React 19 & Modern Component Architecture