Course contentsShow
← React
Lesson 2297 of 2,39650. Performance: Optimization TechniquesFree lesson

Implementing Fixed-Size List Virtualization

Using FixedSizeList to render long lists efficiently by only mounting visible items in the viewport.

Implementing Fixed-Size List Virtualization

What you'll learn: How to use FixedSizeList from React Window to render thousands of list items efficiently by only mounting what's visible.

The Core Concept

Think of scrolling through a massive photo album on your phone—you only see a few photos at a time, not all 10,000 simultaneously. FixedSizeList applies this principle to React lists. Instead of rendering every item in a long array (which creates thousands of DOM nodes), it renders only the items currently visible in the viewport, plus a small buffer. As you scroll, it unmounts off-screen items and mounts new ones coming into view.

This is perfect when every item has the same fixed height—like a list of product cards, chat messages, or data rows.

How It Works

import { FixedSizeList } from 'react-window';

function MyList({ items }) {
  // Define how each row renders
  const Row = ({ index, style }) => (
    <div style={style}>
      {items[index].name}
    </div>
  );

  return (
    <FixedSizeList
      height={600}        // Container height
      itemCount={items.length}  // Total number of items
      itemSize={50}       // Height of each item in pixels
      width="100%"
    >
      {Row}
    </FixedSizeList>
  );
}

FixedSizeList manages the scroll position and calculates which items should be visible. Your Row component receives index (which item to render) and style (positioning managed by React Window—always apply this style).

Why It Matters

With 10,000 items at 50px each, you'd normally create 500,000 pixels of scrollable content with 10,000 DOM nodes. FixedSizeList might only render ~15 visible items, dramatically reducing memory usage and initial render time.

Key Takeaway: FixedSizeList virtualizes long lists with uniform item heights by rendering only visible items, swapping them in and out as you scroll—turning a 10,000-item render problem into a ~15-item problem.