Post

unless refs changed while i wasnโ€™t looking you need to wrap this in `useCallback`, otherwise itโ€™ll call both the cleanup and setup function again every single render

I'm referring to this discussion: bsky.app/profile/gsat...

Sathya@gsathya.bsky.social

Also I just realized a potential bug in the compiler after reading your post! The compiler will automatically move pure functions outside the component, which can break callback ref identity check

0 reposts0 likes

Whatโ€™s the use case for needing to run every render? Seems like a hacky way to do side effects in render

if you create it anonymously during render, react canโ€™t know whether itโ€™s actually the same function from the last render. so it cleans up the previous one and sets up the new one