Avoid unnecessary re-renders and expensive recalculations. Learn exactly when useMemo and useCallback are worth using.

Abdur Razzak
Full-Stack Web Developer
React re-renders a component whenever its state or props change. Every function, object, and array defined inline in the component body gets a new reference on each render, which can trigger unnecessary re-renders in child components.
useMemo returns a memoized value. React only recomputes it when one of the dependencies changes. Use it for expensive filtering, sorting, or transformation of large data sets — not for simple calculations where the memoization overhead outweighs the benefit.
useCallback returns a memoized version of a callback. This is useful when passing callbacks to child components wrapped in React.memo, because the callback reference stays stable between renders as long as the dependencies do not change.
Do not optimise prematurely. First write clear, correct code. Then measure with React DevTools Profiler or Chrome performance tools. Only add useMemo and useCallback where profiling reveals an actual performance problem.