Stop wrapping everything in useCallback In most codebases, useCallback is used as a default 'safety' measure, but 90% of the time, it's adding overhead without any actual performance gain When useCallback ACTUALLY helps: - Child component is wrapped in React.memo() - Function is used as dependency in useEffect - You're optimizing for a REAL performance problem (not guessing) When it hurts: - Extra memory overhead - Dependencies array mistakes = infinite loops - Makes code harder to read - React Compiler (v1.0) handles this automatically now The real truth: You can remove 90% of all useMemo and useCallback in your app and it will be fine might even be faster. Use React Profiler first. Find the actual bottleneck. Then optimize. #React #Performance #JavaScript #WebDevelopment #FrontendTips
Siddique Afridi and Ruslan Volovenko const MemoChild = React.memo(MyComponent) Only re-renders this child if its props have actually changed.
Just use react compiler and be sure your component respect the rules of react to be automatically optimized.
Also makes refactoring more difficult because you can't be sure the memoization was not actually important so it is safer to just keep it or waste more time investigating. Also React Compiler is still tricky to use if your codebase is not fully compatible. E.g. using Tanstack Table.
Is there any difference?
What the difference btw two expression?
Yeah right
Siddique Afridi and Ruslan Volovenko Great catch! The syntax is identical because the function itself doesn't change. The difference is the receiver. As noted in the final comment of the snippet, useCallback is only effective if the child component is wrapped in React.memo. Without that 'MemoizedChild' (which isn't shown in the snippet but mentioned in the comments), the optimization is just memory overhead.