How to Fix React.memo Compare Function
DodaTech
Updated 2026-06-26
1 min read
The Problem
In this quick-fix, you'll learn how to write correct custom comparison for React.memo. This matters because incorrect comparison blocks or fails to prevent re-renders. In real-world applications, this pattern appears in optimizing components with deeply nested objects.
The Wrong Way
const DataGrid = React.memo(({ data }) => <div>...</div>,
(prev, next) => { return prev.data !== next.data; });
DataGrid doesnt re-render when data changes comparison inverted
The Right Way
const DataGrid = React.memo(({ data }) => <div>...</div>,
(prev, next) => { return prev.data === next.data; });
DataGrid correctly skips render when data reference same
Prevention
- Compare function returns true to skip false to re-render
- Default shallow comparison correct for immutable data
- Deep comparison has perf cost
FAQ
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