re: Optimize React Hooks Performance VIEW POST

TOP OF THREAD FULL DISCUSSION
re: your last exmaple or example with useCallback for prevent re-rendering is not working, when every input changed, counter component is re-rendered. ...
 

Hmm, I don't think so...

We don't use useCallback to prevent re-rendering counter component. We use it to memoize our function (the one that add "Hello!" to the "value" state). When you memoize your function with useCallback, the component is still being re-rendered but the returned value of the memoized function is cached. This is very helpful if you want to do expensive task that requires a lot of time.

We put [value] because we always want to update our function when the "value" state changes, because we need "value" state inside our function. So, our function is still being memoized unless the "value" state has changed.

But thanks for the feedback anyway 😃

code of conduct - report abuse