React.memo
In one line
React.memo is a higher-order component that memoizes a component, re-rendering it only when its props change.
In simple words
React.memo wraps a function component and prevents re-renders when the parent re-renders, if the component's props haven't changed. It does a shallow comparison of props by default.
const MemoizedComponent = React.memo(MyComponent) — now, if the parent re-renders but passes the same props, MemoizedComponent skips rendering and reuses the last result.
You can pass a custom comparison function as the second argument: React.memo(MyComponent, areEqual). This is useful when props contain objects or arrays that are structurally equal but referentially different.
Use React.memo for components that render expensively or re-render often with unchanged props. But remember: if the parent always passes new object/array/function props, memo won't help unless you also use useMemo/useCallback to stabilize those props.
Example
const ExpensiveList = React.memo(function ExpensiveList({ items }) {
return items.map(item => <div key={item.id}>{item.name}</div>);
});
// Only re-renders when `items` reference changesReact.memo prevents ExpensiveList from re-rendering when its parent re-renders, as long as the items prop hasn't changed.
Related terms
Related Resources
Related Lessons
- Memoization
Learn React.memo for component memoization.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.