Course contentsShow
← React
Lesson 934 of 2,39624. React.memoFree lesson

List Items with Stable Props: A Common Win

Learn why memoizing list item components often pays off when most items' props remain unchanged.

List Items with Stable Props: A Common Win

What You'll Learn

You'll discover why wrapping list item components with React.memo is one of the most reliable optimization patterns in React.

Why Lists Are Special

When you render a list of items (like todos, comments, or products), each item typically receives data that doesn't change between parent re-renders. For example, a todo item with id: 5 and text: "Buy milk" keeps those same props even when the parent list component re-renders to add a new todo at the end.

Without React.memo, every single item re-renders whenever the parent does—even if only one item changed. With 100 list items, that's 99 unnecessary renders.

The Pattern

const TodoItem = React.memo(({ id, text, completed }) => {
  console.log(`Rendering todo ${id}`);
  return (
    <div className="todo">
      <span>{text}</span>
      <span>{completed ? '✓' : '○'}</span>
    </div>
  );
});

When you add a new todo, only the new TodoItem renders. The existing 99 items get their props compared (cheap shallow check), find they're identical, and skip rendering entirely.

Why It Works So Well

List scenarios hit the sweet spot for React.memo:

  1. Stable props: Item data comes from arrays/databases and rarely changes
  2. High quantity: The more items, the bigger the savings
  3. Simple comparison: Primitive props (strings, numbers, booleans) compare perfectly with shallow equality

Think of it like a factory assembly line: if 99 products haven't changed specifications, why rebuild them when you add product #100?

Key Takeaway: Memoizing list item components is one of React's highest-value optimizations because items naturally have stable props and lists multiply the benefit across many components.