React callback ref is not re-called when the same function stays attached
@victor-lyhan▲ 0 net votes
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.