useVirtual
Virtual scrolling composable for efficiently rendering large lists by only rendering visible items.
Usage
The useVirtual composable efficiently renders large lists by only mounting visible items plus a small overscan buffer. Pass an array of items and configure the item height to get back sliced items, scroll handlers, and positioning values.
0 (rendered) / 10000
Architecture
The rendering pipeline transforms scroll events into visible item ranges:
The following API details are for the useVirtual composable.
Functions
useVirtual
(items: Ref<readonly T[], readonly T[]>, _options?: VirtualOptions) => VirtualContext<T>Virtual scrolling composable for efficiently rendering large lists
Options
onStartReached
(distance: number) => void | Promise<void>The callback to call when the start is reached.
Properties
Methods
Benchmarks
| Operation | Throughput | Latency | Margin |
|---|---|---|---|
| Access computed items 100 times (1,000 items, cached) | 5.4M ops/s | 186ns | ± 0.2% |
| Scroll to start position (1,000 items) | 1.4M ops/s | 692ns | ± 0.6% |
| ScrollTo middle (1,000 items) | 17.9k ops/s | 55.8μs | ± 4.5% |
| Initialize with 1,000 items | 17.4k ops/s | 57.5μs | ± 4.7% |
| Resize single item (1,000 items) | 16.7k ops/s | 59.8μs | ± 9.0% |
Was this page helpful?
