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.

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.

Yah, I appreciated @tkdodo.eu’s mention of this in his blog. I’d love to say this shouldn’t make a huge difference in app code but…I’ve seen app code

0 reposts4 likes

No replies yet.