Virtuoso Grid API Reference

All properties are optional - by default, the component will render empty.

If you are using TypeScript and want to use correctly typed component ref, you can use VirtuosoGridHandle types.

import { VirtuosoGrid, VirtuosoGridHandle } from 'react-virtuoso'
//...
const ref = useRef<VirtuosoGridHandle>(null)
//...
<VirtuosoGrid ref={ref} /*...*/ />

Properties

"components".VirtuosoGridProps

Type parameters

NameDefault
Cunknown

Hierarchy

  • {}

    VirtuosoGridProps

Properties

atBottomStateChange

Optional atBottomStateChange: (atBottom: boolean) => void

Defined in src/components.tsx:552

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


atTopStateChange

Optional atTopStateChange: (atTop: boolean) => void

Defined in src/components.tsx:557

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


components

Optional components: GridComponents<C>

Defined in src/components.tsx:501

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


computeItemKey

Optional computeItemKey: GridComputeItemKey

Defined in src/components.tsx:518

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


context

Optional context: C

Defined in src/components.tsx:506

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


customScrollParent

Optional customScrollParent: HTMLElement

Defined in src/components.tsx:582

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


endReached

Optional endReached: (index: number) => void

Defined in src/components.tsx:536

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.


initialItemCount

Optional initialItemCount: number

Defined in src/components.tsx:491

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


isScrolling

Optional isScrolling: (isScrolling: boolean) => void

Defined in src/components.tsx:530

Called when the list starts/stops scrolling.


itemClassName

Optional itemClassName: string

Defined in src/components.tsx:572

Sets the grid items' className


itemContent

Optional itemContent: GridItemContent<C>

Defined in src/components.tsx:496

Set the callback to specify the contents of the item.


listClassName

Optional listClassName: string

Defined in src/components.tsx:567

Sets the className for the list DOM element


overscan

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

Defined in src/components.tsx:513

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.


rangeChanged

Optional rangeChanged: (range: ListRange) => void

Defined in src/components.tsx:546

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


scrollSeekConfiguration

Optional scrollSeekConfiguration: ScrollSeekConfiguration | false

Defined in src/components.tsx:525

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

Set components.ScrollSeekPlaceholder to change the placeholder content.


scrollerRef

Optional scrollerRef: (ref: HTMLElement | null) => any

Defined in src/components.tsx:562

Provides access to the root DOM element


startReached

Optional startReached: (index: number) => void

Defined in src/components.tsx:541

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


totalCount

totalCount: number

Defined in src/components.tsx:485

The total amount of items to be rendered.


useWindowScroll

Optional useWindowScroll: boolean

Defined in src/components.tsx:577

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

Methods

"components".VirtuosoHandle

Hierarchy

  • VirtuosoHandle

Methods

autoscrollToBottom

autoscrollToBottom(): void

Defined in src/components.tsx:605

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

Returns: void


scrollBy

scrollBy(location: ScrollToOptions): void

Defined in src/components.tsx:601

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

Parameters:

NameType
locationScrollToOptions

Returns: void


scrollIntoView

scrollIntoView(location: FlatScrollIntoViewLocation): void

Defined in src/components.tsx:593

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

Parameters:

NameType
locationFlatScrollIntoViewLocation

Returns: void


scrollTo

scrollTo(location: ScrollToOptions): void

Defined in src/components.tsx:597

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

Parameters:

NameType
locationScrollToOptions

Returns: void


scrollToIndex

scrollToIndex(location: number | FlatIndexLocationWithAlign): void

Defined in src/components.tsx:589

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

Parameters:

NameType
locationnumber | FlatIndexLocationWithAlign

Returns: void