Dev.Lib
arrow_backBack to Blogs
LEVEL_044.4June 27, 20261 min read

Memoization pitfalls

State & Data Flow

Memoizing everything adds comparison overhead and code complexity — profile first.

Summary

Memoizing everything adds comparison overhead and code complexity — profile first. Unstable deps ({}, inline functions) invalidate memo every render. useMemo for cheap ops is slower than recomputing. Memo child but pass unstable callback → still re-renders. Compiler auto-memo may reduce manual need — don't fight it blindly.

Code example

function Parent({ items }) {
  const sorted = useMemo(() => [...items].sort(byName), [items]);
  const onClick = useCallback(() => submit(sorted), [sorted]);
  return <Child items={sorted} onClick={onClick} />;
}

Key points

  • Memoizing everything adds comparison overhead and code complexity — profile first.
  • Unstable deps ({}, inline functions) invalidate memo every render.
  • useMemo for cheap ops is slower than recomputing.
  • Memo child but pass unstable callback → still re-renders.
  • Compiler auto-memo may reduce manual need — don't fight it blindly.

Further reading

Related concepts