Virtualize Large Lists Instead of Rendering All Items
Share
Rendering thousands of DOM nodes for long lists causes slow initial render, high memory usage, and scroll jank. Use virtualization (react-window, TanStack Virtual).
Why This Matters
prevents UI freezes and excessive memory consumption from large lists
Virtualize Large Lists Instead of Rendering All Items
Impact: HIGH (prevents UI freezes and excessive memory consumption from large lists)
Rendering a .map() over thousands of items creates thousands of DOM nodes, all of which the browser must lay out, paint, and keep in memory. This causes multi-second initial render times, high memory usage, and scroll jank as the browser struggles to manage thousands of elements. Virtualization renders only the items currently visible in the viewport (plus a small overscan buffer), typically reducing the DOM node count from thousands to 20-50.
Incorrect (rendering all items in the DOM):
function TransactionList({ transactions }: { transactions: Transaction[] }) { // ❌ If transactions has 10,000 items, this creates 10,000 DOM nodes return ( <div className="transaction-list"> {transactions.map((tx) => ( <TransactionRow key={tx.id} transaction={tx} /> ))} </div> )}
Correct (virtualize with react-window or TanStack Virtual):