Skip to content

How to Fix React.memo Not Preventing Re-renders

DodaTech Updated 2026-06-26 1 min read

The Problem

In this quick-fix, you'll learn how to make React.memo effectively prevent unnecessary re-renders. This matters because React.memo fails due to function and object reference changes. In real-world applications, this pattern appears in large lists chart components form fields that re-render too often.

The Wrong Way

const ExpensiveList = React.memo(({ items, onItemClick }) => {
  console.log('Rendering');
  return items.map(item => <li key={item.id} onClick={()=>onItemClick(item.id)}>{item.name}</li>);
});
function App() {
  const [count, setCount] = useState(0);
  return <><button onClick={()=>setCount(c=>c+1)}>{count}</button>
  <ExpensiveList items={[{id:1,name:'A'}]} onItemClick={(id)=>console.log(id)} /></>;
}
Rendering every time count changes -- inline functions break memo

The Right Way

const ExpensiveList = React.memo(({ items, onItemClick }) => {
  console.log('Rendering');
  return items.map(item => <li key={item.id} onClick={()=>onItemClick(item.id)}>{item.name}</li>);
});
function App() {
  const [count, setCount] = useState(0);
  const items = useMemo(() => [{id:1,name:'A'}], []);
  const handleClick = useCallback((id) => console.log(id), []);
  return <><button onClick={()=>setCount(c=>c+1)}>{count}</button>
  <ExpensiveList items={items} onItemClick={handleClick} /></>;
}
Rendering once -- stable references allow memo to work

Prevention

  • Use useCallback for functions passed to memo children
  • Use useMemo for objects/arrays passed to memo children
  • Inline props break memoization
  • Profile before adding memo

FAQ

### Does React.memo compare props deeply??

No React.memo performs shallow comparison using Object.is. Use custom comparison function (second argument) for deep comparison but be careful about performance.

Should I wrap every component with memo??

No. memo adds comparison cost on every render. Only use for components that re-render often with same props or high in tree with many children.

How to pass children to memo component??

If children are static define outside render or use useMemo. If children change memo cannot prevent re-render as JSX creates new reference each time.

This guide is brought to you by DodaTech — built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro