Prepared Docs

Prepared Docs

⌘K

    Loading navigation…

User

  1. Components
  2. Virtualized List
  3. API and Development

Virtualized list

API and Development

View Source
Submit Issue

VirtualizedList from @prepared911/ui/virtualized-list maps items through renderItem. It keeps every row mounted and skips layout and paint outside the viewport with content-visibility: auto. estimatedItemSize reserves a block size for a row the browser has not laid out. getItemKey stabilizes identity. ref exposes scrollToIndex and scrollToOffset. onEndReached pages the list. emptyContent replaces the list when there are no rows.

Import:

Props

PropTypeNotes
itemsreadonly T[]The full array. Required.
renderItem(item: T, index: number) => ReactNodeRow content. The component owns the li. Required.
estimatedItemSizenumberPixels reserved for a row that has not been laid out. Default 40.
paddingBlockStart, paddingBlockEndSpaceOptionSpace before the first row and after the last, from the space scale.
getItemKey(item: T, index: number) => KeyStable key. Defaults to the index.
emptyContentReactNodeReplaces the list when items is empty.
onEndReached() => voidFires when the end scrolls into view. Paused while a loading or error row renders.
loadingRowReactNodeRendered after the last item.
errorRowReactNodeRendered after loadingRow.
reverseOrderbooleanPins the newest row to the visual block end.
scrollRegionLabelLocalizedMessageName of the scroll region when it is focusable.
refRef<VirtualizedListHandle>scrollToIndex and scrollToOffset.
viewportRefRef<HTMLDivElement>The scroll root.

scrollToIndex(index, { align, behavior }) takes VirtualizedListAlign (Start, Center, End, Nearest). An index outside the list clamps. scrollToOffset(offset, { behavior }) scrolls to a block-axis pixel offset. A smooth behavior becomes instant when motion is reduced.

Replacing @prepared911/ui-core

ui-coreWrite instead
estimateSize={() => 64}estimatedItemSize={64}
renderItem={(item, index, virtualItem) => ...}renderItem={(item, index) => ...}
getItemKey={(index) => id}getItemKey={(item, index) => id}
onScrollEndonEndReached
scrollableProps={{ loading, error, scrollReverse }}loadingRow, errorRow, reverseOrder
paddingStart / paddingEndpaddingBlockStart / paddingBlockEnd
scrollToIndex(i, { align: "center" })scrollToIndex(i, { align: VirtualizedListAlign.Center })
classNameStyle the content renderItem returns

There is no overscan and no VirtualItem export. A table that must unmount off-screen rows uses DataTable.

Basic list

Variable row heights

Pass one estimatedItemSize. Rows that are taller than the estimate keep their real size after the browser lays them out. renderItem can return more content for some indexes; do not pass a per-index size function.

Empty list

Scroll to index

Infinite scroll

Previous

Virtualized List / Usage

Next

Virtualized List / Accessibility

On this page

Props
Replacing @prepared911/ui-core
Basic list
Variable row heights
Empty list
Scroll to index
Infinite scroll