useVirtualList
Virtualizes a large list of fixed or variable-height items so only visible rows are rendered.
The useVirtualList hook virtualizes large lists of fixed or variable-height items by observing scroll position and container height, rendering only the visible slice (plus configurable overscan rows) and providing a scrollToIndex helper.
Installation
Usage
Examples
Fixed-Height Virtualized List (10,000 Rows)
Spread wrapperProps onto an inner wrapper element and position each virtual item at offsetTop.
Variable-Height Rows
Pass a function (index, item) => number as itemHeight to compute dynamic row heights using binary search.
API Reference
UseVirtualListOptions
Configuration options for scroll container target, row height calculation, and overscan count.
containerTargetrequireditemHeightrequiredoverscan?VirtualItem
Metadata and positioning descriptor for each visible virtualized row.
indexrequireditems array.datarequiredindex.offsetToprequiredheightrequiredUseVirtualListReturn
Visible virtual items, total height, wrapper props, and scrollToIndex helper returned by the hook.
virtualItemstotalHeightwrapperPropsscrollToIndexindex into view.indexnumberbehavior?ScrollBehavior