Post

Important little nuance here about callback ref's cleanup function in React 19. If you are assigning a ref object in a callback ref and you decide to add a cleanup function, make sure you re-assign the ref during cleanup.

4 reposts43 likes

the other nuance is that if the function changes, we will disconnect and reconnect on render (like a function dep in an effect). we need to do this because if you reference props, you need the new prop value. so you need a module level function if no props (like you have) or useCallback.