@tanstack/react-virtual
Headless UI for virtualizing large lists and grids in React — render only what's visible to keep performance smooth regardless of dataset size.
@tanstack/react-virtual
ReactHeadless UI for virtualizing large lists and grids in React — render only what's visible to keep performance smooth regardless of dataset size.
Fit
Bundle (gzip)
7.3 kB
24.3 kB raw
Install size includes transitive dependencies. Bundle size is gzipped browser payload.
Freshness
The Problem
Rendering thousands of rows in a table or items in a list causes massive DOM bloat, making pages sluggish and unresponsive. Windowing libraries often dictate fixed item heights and bring opinionated markup.
What It Does
TanStack Virtual calculates which items are in the viewport and provides their sizes and offsets. You render only those items. It supports dynamic item sizes, horizontal and vertical scrolling, grid layouts, and works with any scroll container — no wrapper components required.
Installation
npm install @tanstack/react-virtualUsage Example
import { useVirtualizer } from '@tanstack/react-virtual';
import { useRef } from 'react';
export function VirtualList({ items }: { items: string[] }) {
const parentRef = useRef<HTMLDivElement>(null);
const rowVirtualizer = useVirtualizer({
count: items.length,
getScrollElement: () => parentRef.current,
estimateSize: () => 35,
});
return (
<div ref={parentRef} style={{ height: 400, overflow: 'auto' }}>
<div style={{ height: rowVirtualizer.getTotalSize() }}>
{rowVirtualizer.getVirtualItems().map((virtualItem) => (
<div
key={virtualItem.key}
style={{ position: 'absolute', top: virtualItem.start, height: virtualItem.size }}
>
{items[virtualItem.index]}
</div>
))}
</div>
</div>
);
}Related packages
Fast, composable command palette for React — keyboard-driven search UI with fuzzy filtering and accessible markup out of the box.
@dnd-kit/coreReactModern, accessible drag-and-drop toolkit for React — fully customizable with keyboard support, collision detection, and zero dependencies.
embla-carousel-reactReactLightweight, extensible carousel library for React — smooth scrolling, touch/mouse drag, and full CSS control without prescribing markup.
flagsReactProvider-agnostic feature flags SDK for Next.js and React — toggle features without redeploying.
framer-motionReactProduction-ready declarative animation library for React — gestures, layout animations, and scroll-driven effects with a clean API.