Skip to content

Components

VirtualList<T>

The virtualized list. Renders only the items visible in the viewport and keeps selectedIndex in view.

tsx
import { VirtualList } from "ink-virtual-list";

<VirtualList items={items} renderItem={({ item }) => <Text>{item}</Text>} />;

Required Props

PropTypeDescription
itemsT[]Array of items to render
renderItem(props: RenderItemProps<T>) => ReactNodeRender function for each visible item (props)

Optional Props

PropTypeDefaultDescription
selectedIndexnumber0Index of the selected item; the viewport scrolls to keep it visible
keyExtractor(item: T, index: number) => stringCustom React key per item; defaults to item.id/item.key, then the index
heightnumber | "auto"10Total rendered height in lines, or "auto" to fill the terminal
reservedLinesnumber0Lines subtracted from the terminal height when height="auto"
itemHeightnumber1Lines per item (positive integer; validated at render)
showOverflowIndicatorsbooleantrueShow "N more" markers when items overflow the viewport
overflowIndicatorThresholdnumber1Minimum overflow count before an indicator is shown
renderOverflowTop(count: number) => ReactNodeCustom top overflow indicator (keep to one line)
renderOverflowBottom(count: number) => ReactNodeCustom bottom overflow indicator (keep to one line)
renderScrollBar(viewport: ViewportState) => ReactNodeCustom scrollbar rendered below the list
onViewportChange(viewport: ViewportState) => voidCalled whenever the viewport changes (pass a stable function)

Ref

VirtualList accepts a ref exposing the imperative API — see VirtualListRef and the Imperative Scrolling guide.

Exported Utilities

validateItemHeight(itemHeight)

Validates that a value is a positive integer, throwing a descriptive error otherwise. VirtualList calls this on every render for its itemHeight prop; it's exported for validating user-supplied configuration before it reaches the component.

ts
import { validateItemHeight } from "ink-virtual-list";

validateItemHeight(2); // ok
validateItemHeight(1.5); // throws: itemHeight must be a positive integer

Released under the MIT License.