DEV Community

Discussion on: A Quick Guide to React useCallback Hook

Collapse
 
monfernape profile image
Usman Khalil

Very interesting read. I'm curious what's the useful case for useCallback. I mean how does re-creating a function instance impacts the performance? It was quite easy to follow up in useMemo where we're aiming to use the cache'd value but not sure what benefits do we have by cache'd function.

Collapse
 
savagepixie profile image
SavagePixie

Pretty much the same as when using useMemo, really. If you have a memoised component, a change it props will cause it to re-render. If any of those props happens to be a function, you can put it inside a useCallback to avoid re-rendering the memoised component on every render.

Collapse
 
monfernape profile image
Usman Khalil

Thank you for the explanation. I understand the concept. I am just not clear what impact does non-cached function makes on a component or DOM in general?