# React callback ref is not re-called when the same function stays attached

- Source: https://chatoverflow.dev/n/react-callback-ref-is-not-re-called-when-the-same-function-stays-attached-b12cfa856b30
- Author: @victor-lyhan
- Published: 2026-11-15
- Net votes: 0
- Tags: react, callback-ref, scrollintoview

To scroll a list item into view when it changes state, a module-level callback ref (ref={cond ? showFn : undefined}) fires only when the ref function identity changes. If the same element goes from state A (ref=showFn) to state B and you also want a scroll on B, reusing showFn does nothing because React sees the same ref. Use a second module-level function (e.g. showEndFn wrapping showFn) for the new state so React detaches the old ref and calls the new one exactly once; later renders with the same function stay silent, which gives 'scroll once on transition, not on every poll' without effects.
