If you follow the great tech youtuber Dave Gray He has a series where he breaks down react hooks.
In this article, I will mention five key takeaways that will help you understand react hooks better.
1 Referential Equality:
This means when react goes to reference that function in memory, it is the same one and not a new one.
2 useCallback:
This preserves a function, so that everytime the component re-renders, the function will not get re-created by react. i.e. We are giving the function referential equality
3 useMemo:
This preserves the result of a function that is called, so that it does not have to be re-calculated everytime the component re-renders.
4 useRef:
Its' value stays the same even after a change in state causes the component to re-render.
5 useLayoutEffect:
It is kind of the same as useEffect, but its' side effect must finish running before it will paint to the DOM.
Note: side effect is the code inside useLayoutEffect
Top comments (0)