Chance @chance.dev · Dec 12

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.

43 likes 2 replies

?

Replies

Ricky · Dec 12

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.

Matt Carroll · Dec 17

I had trouble understanding this so I wrote an example of the problem as I understand it in a CodeSandbox: codesandbox.io/p/sandbox/ke...