Virtual List
NewRenders only the rows in view, so 100,000 items scroll like 20. Overscan, scroll-to-row, no dependencies.
Rendering rows 1–0 only
Installation
$ pnpm dlx shadcn@latest add @synccn/virtual-listFirst time in this project? Connect synccn with one command.
Usage
import { VirtualList } from "@/components/ui/virtual-list";<VirtualList items={rows} itemHeight={40} height={400} renderItem={(row) => …} />API reference
Generated from the component's TypeScript types, so it always matches the code.
VirtualList
Renders only the rows in view, so a list of 100,000 items scrolls as smoothly as 20. No dependencies: fixed row heights, overscan, scroll-to-row and correct list semantics.
- itemsrequired
T[]Every item. Only the ones in view are rendered.
- itemHeightrequired
numberHeight of each row in pixels. Rows must all be this tall.
- height
numberDefault
400Height of the scrolling area in pixels.
- overscan
numberDefault
6Extra rows rendered above and below the view, so fast scrolling doesn't flash.
- renderItemrequired
(item: T, index: number) => React.ReactNodeRenders one row.
- getKey
(item: T, index: number) => React.KeyStable key for a row. Defaults to its index.
- scrollToIndex
numberScrolls to this row when it changes.
- onRangeChange
(range: { start: number; end: number }) => voidCalled with the first and last rendered row as you scroll.
- empty
React.ReactNodeShown when there are no items.
- aria-label
stringAccessible name for the list.
Dependencies
Read from the component's imports when the site builds. The CLI installs all of these for you.
Helpers
- lib/utilscn (merges class names)
npm packages
- clsx for cn()
- tailwind-merge for cn()
Accessibility
- Rows keep list semantics with aria-setsize and aria-posinset, so screen readers know the real length.
From the source
Read from this component's code when the site builds, so it can't drift.
- ARIA roles: list, listitem
- ARIA attributes: aria-label, aria-posinset, aria-setsize
- Shows a visible focus ring for keyboard users