MediumPerformance📖 Theory Question

What is virtualization (windowing) and when do you need it?

💡

Hint

Render only visible items in a long list — react-window / react-virtual renders a DOM window into a large dataset

Full Answer

Virtualization renders only the items visible in the viewport instead of the entire list. For 10,000 items, you might only render 20 DOM nodes at a time.

import { FixedSizeList } from 'react-window';

// ❌ Renders all 10,000 DOM nodes immediately
function NaiveList({ items }) {
  return items.map(item => );
}

// ✅ Renders ~20 DOM nodes, recycles them as you scroll
function VirtualList({ items }) {
  const Row = ({ index, style }) => (
    
{/* style positions the row */} {items[index].name}
); return ( {Row} ); }

When to virtualize:

  • Lists with 100+ items where each item has significant DOM
  • Visible performance issues (jank, slow initial render)
  • Tables, feeds, chat history, autocomplete dropdowns

Libraries: react-window (smaller), react-virtual (TanStack, headless), react-virtuoso (variable heights)

💡 Pagination or infinite scroll at ~50 items is often enough and simpler. Reach for virtualization when you genuinely have 500+ items that must all be available without pagination.

More Performance Questions

EasyWhat is React.memo and when does it actually prevent re-renders?EasyWhat is code splitting and lazy loading in React?MediumWhat causes unnecessary re-renders and how do you diagnose them?MediumWhat is the React Profiler and how do you use it to diagnose performance issues?

Practice this in a timed sprint →

5 free questions, no signup required

⚡ Start Sprint