I had a bug in my work code where a component was re-rendering several times - and I realized I needed to wrap the props passed to that component with useCallback
, however - this led to the question of what else I should be wrapping in useCallback
, or should I just blindly wrap all functions within functional components in them.
I came across this blog post: When to useMemo and useCallback
The author claims that in that example, useCallback
is worse for performance - but I don’t get it. Wouldn’t useCallback
create a new function on first render, and re-use the same function on future renders? (Because it’s invoked with an empty dependency list)
Do let me know what I’m missing. I super loved the React course - it’s really empowered my to get into some of the more advanced React topics.