Virtualization — a technique where ONLY visible elements of the list are rendered. If you have 10,000 rows — only 20-30 on screen are rendered.
Why it matters: Without virtualization, rendering 10,000 DOM nodes would create massive performance issues — slow initial render, high memory usage, and sluggish scrolling. Virtualization keeps the DOM small regardless of dataset size. It is essential for chat apps, data tables, log viewers, and any list exceeding a few hundred items.
How virtualization works:
react-window — popular library for virtualization:
1import { FixedSizeList } from "react-window";23const Row = ({ index, style }) => (4 <div style={style}>5 <p>Element {index} — Data from large list</p>6 </div>7);89function VirtualList({ items }) {10 return (11 <FixedSizeList12 height={600} // Container height13 width="100%" // Width14 itemCount={items.length} // Number of elements15 itemSize={50} // Height of each element16 >17 {Row}18 </FixedSizeList>19 );20}
For elements with different heights — VariableSizeList:
1import { VariableSizeList } from "react-window";23const DynamicRow = ({ index, style, data }) => (4 <div style={style}>5 <p>{data[index].text}</p>6 </div>7);89<VariableSizeList10 height={600}11 itemCount={items.length}12 itemSize={(index) => items[index].height || 50}13 itemData={items}14>15 {DynamicRow}16</VariableSizeList>
react-virtuoso — more modern alternative:
1import { Virtuoso } from "react-virtuoso";23<Virtuoso4 style={{ height: "600px" }}5 totalCount={10000}6 itemContent={(index) => <div>Element {index}</div>}7/>
Performance considerations:
itemSize should be accurate — wrong values cause scroll jumps.When to use: