sr✳SHUBHAM RAJFRONTEND ENGINEER
FULL TECHNICAL GUIDEIntermediate3 min read

What does React.memo solve, and what does it not solve?

Know when memoization reduces work and when it simply adds complexity.

React#performance#memoization
THE ANSWER / PLAIN ENGLISH

The idea to remember.

React.memo can skip rendering a component when its props are shallowly equal to the previous props. It does not stop renders caused by that component’s own state or context updates, and it is ineffective when parents recreate object or function props every render. Measure before applying it broadly.

From first example to real project.

Start with the smallest working idea, examine a more detailed example, then look at a real application pattern. Adapt dependencies, error handling and data models to your project.

Basic: understand a render

01 / BEGINNER

A render calculates UI; it does not always change the DOM.

JSX / EXAMPLE
function Greeting({ name }) {
  console.count('Greeting rendered');
  return <h2>Hello, {name}</h2>;
}

Intermediate: memoize derived work

02 / INTERMEDIATE

Memoize an expensive derived value when profiling justifies it.

JSX / EXAMPLE
const visibleRows = React.useMemo(
  () => rows.filter(row => row.label.includes(query)),
  [rows, query]
);

Real scenario: stabilize props

03 / REAL SCENARIO

Only optimize a frequently updated dashboard after measuring.

JSX / EXAMPLE
const Chart = React.memo(function Chart({ data }) {
  return <Graph data={data} />;
});
function Dashboard({ records, filter }) {
  const data = React.useMemo(() => aggregate(records, filter), [records, filter]);
  return <Chart data={data} />;
}

Try it in your own words.

Explain what does React.memo solve, and what does it not solve without looking at the code. Then modify the intermediate example, describe one trade-off and identify when the real-world pattern fits.

Keep learning here.

Explore more in-depth guides, exercises and related interview questions in this library.

Browse React study guides ↗
← Back to question library

Have something
in mind?

Start a conversation