React.memo Component Memoization

Last updated: 2026-11-02

React.memo Component Memoization

Wrapping a component in React.memo lets it skip a re-render when its props stay equal in a shallow comparison, reusing the previous output as is. It suits child components that are expensive to render and receive stable props, and the benefit is biggest when the parent refreshes often, for example while typing or moving the mouse. Because the comparison is shallow, a new object or function in the props defeats the cache, so memo usually has to be paired with useMemo or useCallback.

GroupEffects & Performance
KindAPI
SinceReact 16.6

ℹ️ Info The editor transpiles JSX to JavaScript and renders the real UI in a sandbox; components mount automatically — no manual render call needed.

📝 Syntax

const MemoList = memo(function List({ items, onSelect }) {
  return items.map(it => <Row key={it.id} item={it} onSelect={onSelect} />)
})
// equal props after a shallow comparison mean the render is skipped
// the second argument can customize the comparison: memo(Cmp, (prev, next) => equal)

⚙️ Parameters

ComponentThe component to wrap, usually a presentational component that is expensive to render.
areEqual (optional)A custom comparison function (prevProps, nextProps) => boolean; returning true means the props are equal and the render is skipped.

Returns:Returns a memoized copy of the component, used exactly like the original one.

▶ Example

The example runs out of the box: it auto-renders when expanded, and edits take effect instantly.

Output:

Clicking the button repeatedly only updates the counter text and the console stops printing "The list rendered" — the items reference never changes, so memo lets the whole list skip the re-render.

💡 Key Points

💡 Tip memo only performs a shallow comparison of props: a function or object created on every render breaks the cache, so pair it with useCallback or useMemo.
ℹ️ Info A component that receives children is usually a poor candidate for memo — children is a new element reference on every render.
⚠️ Warning Do not wrap every component in memo without thinking: the wrapper has a comparison cost too, so find the real hot spots with the DevTools Profiler first.
More case studies coming soon.

📚 Related Tutorials

❓ FAQ

Q What is the difference between memo and useMemo?
A memo is a higher-order component that caches the render output of a component, while useMemo is a hook that caches one computed value.
Q Why does a memoized component still re-render?
A Most likely the props contain an object, array or function created on every render, so the shallow comparison can never be equal — stabilize the references with useMemo or useCallback.
Q How do I write the second argument areEqual?
A It receives (prev, next) and returns true when they count as equal so the render can be skipped; use it only when the shallow comparison really does not fit, such as comparing one deeply nested field.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏