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 are debounce and throttle? When do you use each?EasyWhat causes memory leaks in JavaScript and how do you detect them?EasyWhat is the difference between reflow and repaint, and how do you avoid layout thrashing?MediumWhat is lazy loading and code splitting?

Practice this in a timed sprint →

5 free questions, no signup required

⚡ Start Sprint