React Virtuoso

4.18.5 · active · verified Sun Apr 19

React Virtuoso is a high-performance virtual scroll component library designed for efficiently rendering large lists, grids, and tables in React applications. It achieves this by virtualizing items, meaning only the visible elements are rendered, significantly optimizing performance and memory usage, especially for thousands of items. The current stable version is 4.18.5, and the project maintains an active release cadence with frequent patch and minor updates. Key differentiators include automatic handling of variable and dynamic item sizes without requiring manual measurement, responsive container sizing that adapts seamlessly to parent and viewport changes (including complex flexbox layouts), and robust support for bi-directional endless scrolling through `startReached` and `endReached` callbacks. The library also offers specialized components like `GroupedVirtuoso` for lists with sticky headers, `VirtuosoGrid` for responsive grid layouts, and `TableVirtuoso` for virtualized tables, providing extensive customization options and integration capabilities with popular UI libraries like shadcn/ui, MUI, and Mantine.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a basic `Virtuoso` component rendering a list of 5000 items with simulated variable heights within a fixed-height container, showcasing its core virtualization capabilities.

import { Virtuoso } from 'react-virtuoso';
import React from 'react';

const generateItems = (count: number) =>
  Array.from({ length: count }, (_, i) => ({
    id: i,
    text: `Item ${i + 1}`,
    height: Math.random() * 50 + 50 // Simulate variable heights
  }));

export default function MyVirtualizedList() {
  const items = React.useMemo(() => generateItems(5000), []);

  return (
    <div style={{ height: '400px', border: '1px solid #ccc', margin: '20px' }}>
      <h2 style={{ padding: '10px', margin: 0, background: '#f0f0f0' }}>Large Virtual List Example</h2>
      <Virtuoso
        style={{ height: 'calc(100% - 60px)' }} // Adjust for title height
        totalCount={items.length}
        itemContent={(index) => (
          <div
            style={{
              padding: '15px 10px',
              borderBottom: '1px solid #eee',
              background: index % 2 === 0 ? '#fafafa' : 'white',
              height: items[index].height // Use pre-calculated variable height
            }}
          >
            <strong>{items[index].text}</strong>: This is content for item {index}.
            It demonstrates variable height functionality.
          </div>
        )}
        // Optional: Implement infinite scroll
        // endReached={() => {
        //   console.log('End of list reached, fetching more data...');
        //   // In a real app, you would fetch more items here
        // }}
        // overscan={200} // Render 200px before/after viewport for smoother scroll
      />
    </div>
  );
}

view raw JSON →