hardFrontend

When does `React.memo` do nothing — or actually hurt performance?

404 views
01

Understand the problem

The limits and costs of memoizing components.

reactperformancememoization
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Stuck? AI Nudge Available

Get a conceptual hint to guide your logic without spoiling the final implementation.

03

Study the solution

The solution is waiting

Give it an honest attempt first — then compare your thinking with the full walkthrough.

04

Explore the playground snippets

memo skips re-render on stable props
Run Playground
import { useState, memo, useRef } from 'react';

const Child = memo(function Child({ label }) {
  const renders = useRef(0);
  renders.current++;
  return <p>{label} child rendered <b>{renders.current}</b> time(s)</p>;
});

export default function App() {
  const [count, setCount] = useState(0);
  return (
    <div style={{ fontFamily: 'sans-serif', padding: 24 }}>
      <p>Parent count: {count}</p>
      <button onClick={() => setCount((c) => c + 1)}>Re-render parent</button>
      <Child label="Memoized" />
      <p style={{ color: '#666' }}>Its prop is stable, so the memoized child does NOT re-render when the parent updates.</p>
    </div>
  );
}
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.