Skip to content
Source
Sign inSign up
TanStack/virtual
Open History to see the last commit

virtual-item.md

65 lines1.7 KB

1---
2title: VirtualItem
3---
4​
5The `VirtualItem` object represents a single item returned by the virtualizer. It contains information you need to render the item in the coordinate space within your virtualizer's scrollElement and other helpful properties/functions.
6​
7```tsx
8export interface VirtualItem {
9 key: string | number | bigint
10 index: number
11 start: number
12 end: number
13 size: number
15```
16​
17The following properties and methods are available on each VirtualItem object:
18​
19### `key`
20​
21```tsx
22key: string | number | bigint
23```
24​
25The unique key for the item. By default this is the item index, but should be configured via the `getItemKey` Virtualizer option.
26​
27### `index`
28​
29```tsx
30index: number
31```
32​
33The index of the item.
34​
35### `start`
36​
37```tsx
38start: number
39```
40​
41The starting pixel offset for the item. This is usually mapped to a css property or transform like `top/left` or `translateX/translateY`.
42​
43### `end`
44​
45```tsx
46end: number
47```
48​
49The ending pixel offset for the item. This value is not necessary for most layouts, but can be helpful so we've provided it anyway.
50​
51### `size`
52​
53```tsx
54size: number
55```
56​
57The size of the item. This is usually mapped to a css property like `width/height`. Before an item is measured with the `VirtualItem.measureElement` method, this will be the estimated size returned from your `estimateSize` virtualizer option. After an item is measured (if you choose to measure it at all), this value will be the number returned by your `measureElement` virtualizer option (which by default is configured to measure elements with `getBoundingClientRect()`).
58​
59### `lane`
60​
61```tsx
62lane: number
63```
64​
65The lane index of the item. In regular lists it will always be set to `0` but becomes useful for masonry layouts (see variable examples for more details).