List
Render caller-defined rows with optional virtual scrolling.
- Review onboarding designsElena
- Fix invoice roundingMarcus
- Draft 0.9 release notesPriya
Anatomy#
Usage#
Use List when the caller owns each row’s markup and needs a stable collection surface. Pass items
and an itemRender component; List does not take row content through children. Add a
virtualizer for large collections only when ordinary rendering becomes costly.
Rows#
itemRender: receives{ item, index, rowProps }. When using avirtualizer, spreadrowPropsonto the outer row element for positioning and measurement.as: the root defaults to<ul>and always carriesrole="list", so render list-item semantics in each row or select another root element withas. TypeScript infers item and root element types fromitemsandas.emptyRender: renders whenitemsis empty orundefined.
Virtualization#
createListVirtualizer is an optional adapter from moraine/virtualizer (requires @tanstack/virtual-core). The List root is the scroll container, so give it a bounded height and overflow-y-auto. Row count and scroll behavior follow the estimated or measured row sizes.
Read the Virtualization guide for setup, row measurements, stable keys, and keyboard navigation.
Edge loading#
onTopReached and onBottomReached fire once each time scrolling reaches the top or bottom edge of an overflowing list; neither fires for the initial scroll position. Combine onBottomReached with scrollThreshold to request the next page shortly before the end.
Drag to reorder#
createListSortable is an optional adapter from moraine/dnd (requires @dnd-kit/dom). List has no drag props; the sortable composes through itemRender:
- Wrap the list in
sortable.Provider. - Call
sortable.useRow(context)insideitemRenderand spreadrow.propsonto the row element. - Update your list state from
onReorder.
row.props preserves context.rowProps and adds the drag ref, data-dragging, and data-drop-position.
When combining with a virtualizer, pass rangeExtractor: sortable.rangeExtractor to createListVirtualizer so the dragged row stays mounted while scrolled out of view. Read the Drag and drop guide for handles, keyboard dragging, and options.
Examples#
Empty state#
emptyRender renders when items is empty. List does not invent empty copy; pass the row markup you
want shown.
Virtualization#
Use createListVirtualizer when tens of thousands of rows would otherwise mount at once. Spread
context.rowProps onto the measured row element.
Sortable#
The grip button is the drag handle, so it also starts a keyboard drag with Space or Enter. Arrow keys move to the next row, and Space, Enter, or Escape ends the drag.
Sortable with virtualization#
Drag a row toward the list edge to scroll. The row is its own handle here.
Dynamic height#
Estimate a larger size when row height varies, and let the virtualizer measure after mount.
API Reference#
Props#
Renders a <ul> element by default.