Skip to content

Virtuoso

Virtuoso<ItemData, Context>(props): ReactElement

A virtualized list component for efficiently rendering large datasets. Automatically measures and handles variable-sized items without configuration.

Type ParameterDefault typeDescription
ItemDataanyThe type of data items in the list
ContextanyThe type of additional context passed to callbacks
ParameterTypeDescription
propsVirtuosoProps<ItemData, Context> & objectVirtuosoProps

ReactElement

tsx

The props for the Virtuoso component.

Type ParameterDescription
DataThe type of data items in the list
ContextThe type of additional context passed to callbacks

Setting alignToBottom to true aligns the items to the bottom of the list if the list is shorter than the viewport. Use followOutput property to keep the list aligned when new items are appended.


optional atBottomStateChange: (atBottom) => void

Called with true / false when the list has reached the bottom / gets scrolled up. Can be used to load newer items, like tail -f.

ParameterType
atBottomboolean

void


The property accepts pixel values.

By default 4. Redefine to change how much away from the bottom the scroller can be before the list is not considered not at bottom.


optional atTopStateChange: (atTop) => void

Called with true / false when the list has reached the top / gets scrolled down.

ParameterType
atTopboolean

void


The property accepts pixel values.

By default 0. Redefine to change how much away from the top the scroller can be before the list is not considered not at top.


Use the components property for advanced customization of the elements rendered by the list.


If specified, the component will use the function to generate the key property for each list item.


Additional context available in the custom components and content callbacks


Pass a reference to a scrollable parent element, so that the list won’t wrap in its own.


The data items to be rendered. If data is set, the total count will be inferred from the length of the array.


By default, the component assumes the default item height from the first rendered item (rendering it as a “probe”).

If the first item turns out to be an outlier (very short or tall), the rest of the rendering will be slower, as multiple passes of rendering should happen for the list to fill the viewport.

Setting defaultItemHeight causes the component to skip the “probe” rendering and use the property value as default height instead.


optional endReached: (index) => void

Gets called when the user scrolls to the end of the list. Receives the last item index as an argument. Can be used to implement endless scrolling.

ParameterType
indexnumber

void


Use when implementing inverse infinite scrolling - decrease the value this property in combination with data or totalCount to prepend items to the top of the list.

Warning: the firstItemIndex should be a positive number, based on the total amount of items to be displayed.


Can be used to improve performance if the rendered group header items are of known size. Setting it causes the component to skip measuring group headers. The value is in pixels. This value has no effect if fixedItemHeight is not set.


Can be used to improve performance if the rendered items are of known size. Setting it causes the component to skip item measurements.


If set to true, the list automatically scrolls to bottom if the total count is changed. Set to "smooth" for an animated scrolling.

By default, followOutput scrolls down only if the list is already at the bottom. To implement an arbitrary logic behind that, pass a function:

tsx

Set to customize the wrapper tag for the header and footer components (default is div).


Use when you have items with widely varying heights and can estimate each item’s height upfront.

Pass an array of estimated heights for each item (by index). This helps the component calculate a more accurate initial total height for the list, reducing layout shifts during initial scrolling.

The estimates don’t need to be exact - they’re used to build the initial size tree before actual measurements are taken. Once items are rendered and measured, their real heights replace the estimates.

tsx

When set, turns the scroller into a horizontal list. The items are positioned with inline-block.


increaseViewportBy?: number | { bottom: number; top: number; }

Section titled “increaseViewportBy?: number | { bottom: number; top: number; }”

The property accepts pixel values.

Set the increaseViewportBy property to artificially increase the viewport size, causing items to be rendered before outside of the viewport. The property causes the component to render more items than the necessary, but can help with slow loading content. Using { top?: number, bottom?: number } lets you set the increase for each end separately.


Use for server-side rendering - if set, the list will render the specified amount of items regardless of the container / item size.


Set this value to offset the initial location of the list. Warning: using this property will still run a render cycle at the scrollTop: 0 list window. If possible, avoid using it and stick to initialTopMostItemIndex instead.


Set to a value between 0 and totalCount - 1 to make the list start scrolled to that item. Pass in an object to achieve additional effects similar to scrollToIndex.


optional isScrolling: (isScrolling) => void

Called when the list starts/stops scrolling.

ParameterType
isScrollingboolean

void


Set the callback to specify the contents of the item.


Allows customizing the height/width calculation of Item elements.

The default implementation reads el.getBoundingClientRect().height and el.getBoundingClientRect().width.


optional itemsRendered: (items) => void

Called with the new set of items each time the list items are rendered due to scrolling.

ParameterType
itemsListItem<Data>[]

void


set to LogLevel.DEBUG to enable various diagnostics in the console, the most useful being the item measurement reports.

Ensure that you have “all levels” enabled in the browser console too see the messages.


minOverscanItemCount?: number | { bottom: number; top: number; }

Section titled “minOverscanItemCount?: number | { bottom: number; top: number; }”

Set the minimum number of items to render before and after the visible viewport boundaries. This is useful when rendering items with dynamic or very tall content, where the pixel-based increaseViewportBy may not be sufficient to prevent empty areas during rapid resizing or scrolling. Using { top?: number, bottom?: number } lets you set the count for each end separately.


overscan?: number | { main: number; reverse: number; }

Section titled “overscan?: number | { main: number; reverse: number; }”

The property accepts pixel values.

Set the overscan property to make the component “chunk” the rendering of new items on scroll. The property causes the component to render more items than the necessary, but reduces the re-renders on scroll. Setting { main: number, reverse: number } lets you extend the list in both the main and the reverse scrollable directions. See the increaseViewportBy property for a similar behavior (equivalent to the overscan in react-window).


optional rangeChanged: (range) => void

Called with the new set of items each time the list items are rendered due to scrolling.

ParameterType
rangeListRange

void


pass a state obtained from the getState() method to restore the list state - this includes the previously measured item sizes and the scroll location. Notice that you should still pass the same data and totalCount properties as before, so that the list can match the data with the stored measurements. This is useful when you want to keep the list state when the component is unmounted and remounted, for example when navigating to a different page.


optional scrollerRef: (ref) => any

Provides access to the root DOM element

ParameterType
refHTMLElement | Window | null

any


optional scrollIntoViewOnChange: (params) => false | ScrollIntoViewLocation | null | undefined

Implement this callback if you want to adjust the list position when the list total count changes. Return a ScrollIntoViewLocation object to scroll to a specific item, or falsey value to avoid scrolling. Use the context contents if you need to implement custom logic based on the current state of the list.

ParameterType
params{ context: Context; scrollingInProgress: boolean; totalCount: number; }
params.contextContext
params.scrollingInProgressboolean
params.totalCountnumber

false | ScrollIntoViewLocation | null | undefined


Use to display placeholders if the user scrolls fast through the list.

Set components.ScrollSeekPlaceholder to change the placeholder content.


skipAnimationFrameInResizeObserver?: boolean

Section titled “skipAnimationFrameInResizeObserver?: boolean”

When set, the resize observer used to measure the items will not use requestAnimationFrame to report the size changes. Setting this to true will improve performance and reduce flickering, but will cause benign errors to be reported in the console if the size of the items changes while they are being measured. See https://github.com/petyosi/react-virtuoso/issues/1049 for more information.


optional startReached: (index) => void

Called when the user scrolls to the start of the list.

ParameterType
indexnumber

void


Set the amount of items to remain fixed at the top of the list.

For a header that scrolls away when scrolling, check the components.Header property.


The total amount of items to be rendered.


optional totalListHeightChanged: (height) => void

Called when the total list height is changed due to new items or viewport resize.

ParameterType
heightnumber

void


Uses the document scroller rather than wrapping the list in its own.


Exposes the Virtuoso component methods for imperative control. Access via ref on the Virtuoso component.

autoscrollToBottom(): void

Use this with combination with follow output if you have images loading in the list. Listen to the image loading and call the method.

void


getState(stateCb): void

Obtains the internal size state of the component, so that it can be restored later. This does not include the data items.

ParameterTypeDescription
stateCbStateCallbackCallback that receives the state snapshot

void


scrollBy(location): void

Scrolls the component with the specified amount. See ScrollToOptions (MDN)

ParameterTypeDescription
locationScrollToOptionsThe scroll offset options

void


scrollIntoView(location): void

Scrolls the item into view if necessary. See the website example for an implementation.

ParameterTypeDescription
locationFlatScrollIntoViewLocationThe scroll into view location options

void


scrollTo(location): void

Scrolls the component to the specified location. See ScrollToOptions (MDN)

ParameterTypeDescription
locationScrollToOptionsThe scroll position options

void


scrollToIndex(location): void

Scrolls the component to the specified item index. See IndexLocationWithAlign for more options.

ParameterTypeDescription
locationnumber | FlatIndexLocationWithAlignThe item index or location with alignment options

void


Customize the Virtuoso rendering by passing a set of custom components.

tsx

VirtuosoProps.components for usage in Virtuoso

Type ParameterDefault typeDescription
DataunknownThe type of data items in the list
ContextunknownThe type of additional context passed to components

Set to render a custom UI when the list is empty.


Set to render a component at the bottom of the list.


Group?: ComponentType<Pick<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style" | "children"> & object & ContextProp<Context>>

Section titled “Group?: ComponentType<Pick<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style" | "children"> & object & ContextProp<Context>>”

Set to customize the group item wrapping element. Use only if you would like to render list from elements different than a div.


Set to render a component at the top of the list.

The header remains above the top items and does not remain sticky.


Item?: ComponentType<Pick<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style" | "children"> & object & ContextProp<Context>>

Section titled “Item?: ComponentType<Pick<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style" | "children"> & object & ContextProp<Context>>”

Set to customize the item wrapping element. Use only if you would like to render list from elements different than a div.


List?: ComponentType<Pick<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style" | "children"> & RefAttributes<HTMLDivElement> & object & ContextProp<Context>>

Section titled “List?: ComponentType<Pick<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style" | "children"> & RefAttributes<HTMLDivElement> & object & ContextProp<Context>>”

Set to customize the items wrapper. Use only if you would like to render list from elements different than a div.


Scroller?: ComponentType<Pick<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style" | "tabIndex" | "children"> & RefAttributes<HTMLDivElement> & object & ContextProp<Context>>

Section titled “Scroller?: ComponentType<Pick<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "style" | "tabIndex" | "children"> & RefAttributes<HTMLDivElement> & object & ContextProp<Context>>”

Set to customize the outermost scrollable element. This should not be necessary in general, as the component passes its HTML attribute props to it.


Set to render an item placeholder when the user scrolls fast. See the scrollSeek property for more details.


Set to customize the top list item wrapping element. Use if you would like to render list from elements different than a div or you want to set a custom z-index for the sticky position.


ItemContent<Data, Context> = (index, data, context) => React.ReactNode

Callback type for rendering item content in a Virtuoso list.

Type ParameterDescription
DataThe type of the data item
ContextThe type of context passed from the component
ParameterType
indexnumber
dataData
contextContext

React.ReactNode

tsx

ItemProps<Data> = Pick<React.ComponentProps<"div">, "children" | "style"> & object

Passed to the Components.Item custom component

number

number

number

Data

Type Parameter
Data

ListProps = Pick<React.ComponentProps<"div">, "children" | "style"> & React.RefAttributes<HTMLDivElement> & object

Passed to the Components.List custom component

string


ListRootProps = Omit<React.HTMLProps<HTMLDivElement>, "data" | "ref">


Passed to the Components.ScrollSeekPlaceholder custom component

The group index if this placeholder represents a group header


number

The height of the placeholder in pixels


number

The index of the item being replaced by the placeholder


"group" | "item"

Whether this placeholder represents a group header or a regular item


TopItemListProps = Pick<React.ComponentProps<"div">, "children" | "style">


const VirtuosoMockContext: Context<VirtuosoMockContextValue | undefined>

React context for mocking Virtuoso component measurements in tests. Wrap your Virtuoso component with this provider to bypass DOM measurements.

tsx

Mock context value for testing Virtuoso components. Provides fixed dimensions to bypass DOM measurements.

number

Fixed height for each item in pixels


number

Fixed viewport height in pixels