React Native · Components
VirtualList
A virtual list for very long lists: only the visible items (and a bit more) are rendered.
3 exports
Live example
The preview runs in the browser with the web component; the native component takes the same props and looks the same on iOS and Android.
Preview
Person 1
Long note: this row is taller than the others because it has a description that wraps onto two lines.
Person 2
Person 3
Person 4
Person 5
Person 6
Person 7
Person 8
Long note: this row is taller than the others because it has a description that wraps onto two lines.
Person 9
Person 10
Person 11
Person 12
Person 13
Person 14
Person 15
Long note: this row is taller than the others because it has a description that wraps onto two lines.
Person 16
Person 17
Person 18
Person 19
Code
Events
- Events appear here when you interact with the preview.
Import
VirtualList
componentA virtual list for very long lists: only the visible items (and a bit more) are rendered. Wraps React Native's FlatList with the library's rules: infinite loading (onLoadMore, Promise awaited, retry on error), empty state, pull to refresh and measurement-free layout with a fixed height. Same prop names as the web VirtualList.
Examples
VirtualListHandle
interfaceMethods of the VirtualList ref.
| Name | Type | Description |
|---|---|---|
scrollToIndex | (index: number, options?: { align?: "start" | "center" | "end"; smooth?: boolean; }) => void | Scrolls to an item. align: the item comes to the start, center or end. |
scrollToTop | (options?: { smooth?: boolean; }) => void | Scrolls to the very top. |
VirtualListProps
interfaceVirtualList props.
| Name | Type | Default | Description |
|---|---|---|---|
ref? | Ref<VirtualListHandle> | Ref: scrollToIndex, scrollToTop. | |
items | readonly T[] | Items. | |
renderItem | (item: T, index: number) => ReactNode | Renders an item. | |
getKey? | (item: T, index: number) => string | number | its index | The item's stable key. |
estimateSize? | number | Item height (width when horizontal). With a fixed number the list lays out without measuring and jumps to a distant item instantly (the fastest path). | |
overscan? | number | 5 | How many times the visible area is rendered ahead. |
gap? | number | 0 | Gap between items (pixels). |
horizontal? | boolean | Horizontal list. | |
height? | number | List height; fills the container if omitted (flex: 1). | |
empty? | ReactNode | Content shown when the list is empty (e.g. <EmptyState />). | |
onLoadMore? | () => unknown | Called when nearing the end (infinite list). If it returns a Promise it is not called again until it settles; on error "Try again" appears at the bottom. | |
onError? | (error: unknown) => void | When onLoadMore fails. | |
hasMore? | boolean | true | Whether there are more items; onLoadMore is not called when false. |
loading? | boolean | Loading state from outside (indicator at the bottom). | |
threshold? | number | 600 | How many pixels before the end loading starts. |
header? | ReactNode | Content at the start of the list. | |
onRefresh? | () => unknown | Pull to refresh: if it returns a Promise the indicator spins until it settles. | |
style? | StyleProp<ViewStyle> | List style. | |
contentStyle? | StyleProp<ViewStyle> | Style of the content container (for padding). |