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.
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.
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?
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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.
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 auseCallback
to avoid re-rendering the memoised component on every render.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?