Overview
TanStack Virtual provides virtualization logic for rendering only visible items in large lists, grids, and tables. It calculates which items are in the viewport and positions them with absolute positioning, keeping DOM node count minimal regardless of dataset size.
Package: @tanstack/react-virtual
Core: @tanstack/virtual-core (framework-agnostic)
Installation
Core Pattern
Virtualizer Options
Required
Optional
Virtualizer API
VirtualItem Properties
Dynamic/Variable Heights
Use measureElement ref for items with unknown heights:
Horizontal Virtualization
Grid Virtualization (Two Virtualizers)
Window Scrolling
Infinite Scrolling
Sticky Items
Smooth Scrolling
Best Practices
- Overestimate
estimateSize- prevents scroll jumps (items shrinking causes issues) - Increase
overscan(3-5) to reduce blank flashing during fast scrolling - Use
transform: translateY()overtopfor GPU-composited positioning - Add
data-indexattribute when usingmeasureElementfor dynamic sizing - Don't set fixed height on dynamically measured items
- Use
getItemKeyfor stable keys when items can reorder - Use
gapoption instead of margins (margins interfere with measurement) - Use
paddingStart/Endinstead of CSS padding on the container - Use
enabled: falseto pause when the list is hidden - Memoize callbacks (
estimateSize,getItemKey,rangeExtractor) - Use
will-change: transformCSS on items for GPU acceleration
Common Pitfalls
- Setting fixed height on dynamically measured items
- Using CSS margins instead of the
gapoption - Forgetting
data-indexwithmeasureElement - Not providing
position: relativeon the inner container - Underestimating
estimateSize(causes scroll jumps) - Setting
overscantoo low for fast scrolling (blank items) - Forgetting to subtract
scrollMarginfromtranslateYin window scrolling - Not memoizing the
estimateSizefunction (causes re-renders)


