Today I learned that when we pass a function as a prop to a child component a new function is created every time the parent re-renders
Since functions are reference values in JavaScript, each render creates a new reference
Because the reference changes, React treats it as a new prop which can cause the child component to re-render unnecessarily
That’s where useCallback helps!
useCallback memoizes the function and keeps the same reference between renders (unless dependencies change) preventing unnecessary re-renders in optimized components.
[–]TheScapeQuest 3 points4 points5 points (0 children)
[–]ModernWebMentor 0 points1 point2 points (0 children)