useListVirtualizer

Virtualization hook for rendering large lists efficiently

Installation

Overview

useListVirtualizer provides virtualization for large lists using TanStack Virtual. It handles scroll positioning, item measurement, and keyboard navigation, making it easy to render thousands of items without performance issues.

When to use:

  • Lists with 100+ items
  • Command menus, autocompletes, or selects with large datasets
  • Any scrollable list where DOM node count impacts performance

Usage

Example with Command

Performance Tips

For optimal scroll performance with large lists:

  1. Use useDeferredValue for search queries - Prevents filtering from blocking scroll rendering. Use the resolved pattern to avoid stale results when clearing:

  2. Use nativeScroll on CommandVirtualizedList - Avoids custom scroll container overhead for smoother fast scrolling.

API Reference

Options

Prop

Return Value

PropertyTypeDescription
rootPropsobjectSpread on root component. Includes virtualized, items, filteredItems, onItemHighlighted
scrollRef(el: HTMLDivElement | null) => voidRef callback for the scroll container
measureRef(el: HTMLDivElement | null) => voidRef callback for each item (enables dynamic heights)
totalSizenumberTotal height of all virtual items in pixels
virtualItemsVirtualItem[]Array of virtual items to render
getItem(virtualItem) => T | undefinedGet the data item for a virtual item
getItemStyle(virtualItem) => CSSPropertiesGet positioning styles for a virtual item
getItemProps(virtualItem) => objectGet aria attributes (aria-setsize, aria-posinset, data-index, index)

Used By