DEV Community

React: useCallback hooks simple explanation

Azrul Aziz on June 17, 2019

useCallback(function, [dependecies]) Enter fullscreen mode Exit fullscreen mode useCallback is one of the new featu...
Collapse
 
cathalmacdonnacha profile image
Cathal Mac Donnacha ๐Ÿš€

I think it's worth pointing out that using useCallback can actually make your app even slower and may damage performance: dmitripavlutin.com/dont-overuse-re...

So the function is still created on a re-render, it just returns the same function reference as before. Therefore I think this article may be a bit misleading to readers thinking they should always implement useCallback().

Collapse
 
rohimchou profile image
RohimChou

typo: it Returns a memoized memorized callback.

Collapse
 
nasht profile image
Nathan Hazout

No, memoized is the correct word: en.wikipedia.org/wiki/Memoization

Collapse
 
rohimchou profile image
RohimChou
  1. I am a dumb-dumb
  2. Thank you for this !!
Thread Thread
 
herman_pervin profile image
Pudina

Neither of you was correct. Memo is not a real word. It's short for memorandum, so it should be memorandumization. If you're going to spell it with memo, then at least include a hyphen: memo-ization.

Collapse
 
herman_pervin profile image
Pudina

Neither of you was correct. Memo is not a real word. It's short for memorandum, so it should be memorandumization. If you're going to spell it with memo, then at least include a hyphen: memo-ization.

Collapse
 
minbelapps profile image
minbelapps • Edited

Nice article but I missed the answer to this comment from React docs:

The array of dependencies is not passed as arguments to the function. Conceptually, though, thatโ€™s what they represent: every value referenced inside the function should also appear in the dependencies array.

So it's not clear is it a dependency array or is it an array for cache'ing control.

The thing is, that all those useCallbacks work with empty array `[]` and from this point, it's not the dependency array.

Collapse
 
julescsv profile image
Jules Njik

Clean and simple.
Good Job!

Collapse
 
hekkeynwa profile image
Henrik Juhl

Excellent explanation thanks