Post

One of my favorite changes in v19. Callback refs are really good. I'll write another blogpost soon because my recommendation to wrap in useCallback might not be 100% correct.

Yeah, I'm curious about that. I recognize this pattern from SolidJS but I imagine React will run this ref callback on every re-render. Could that be an issue for, say, `document.addEventListener` use cases?

0 reposts5 likes

If you can extract the function outside of the component, you won't have that issue. If your code still runs correctly (just not very performant), wrap in useCallback.