Convert Figma logo to code with AI

bvaughn logoreact-virtualized

React components for efficiently rendering large lists and tabular data

26,264
3,055
26,264
305

Top Related Projects

5,365

🤖 Headless UI for Virtualizing Large Element Lists in JS/TS, React, Solid, Vue and Svelte

React components for efficiently rendering large lists and tabular data

The most powerful virtual list component for React

5,365

🤖 Headless UI for Virtualizing Large Element Lists in JS/TS, React, Solid, Vue and Svelte

A tiny but mighty 3kb list virtualization library, with zero dependencies 💪 Supports variable heights/widths, sticky items, scrolling to index, and more!

Quick Overview

React Virtualized is a popular React library for efficiently rendering large lists and tabular data. It uses virtualization techniques to render only the visible elements, significantly improving performance for applications dealing with large datasets.

Pros

  • Greatly improves performance for rendering large lists and tables
  • Supports both fixed and variable height rows
  • Provides a variety of components for different use cases (List, Grid, Table, etc.)
  • Highly customizable with extensive API and theming options

Cons

  • Learning curve can be steep for beginners
  • Some edge cases and complex layouts may require additional workarounds
  • Documentation, while comprehensive, can be overwhelming for new users
  • Occasional issues with scrolling behavior in certain scenarios

Code Examples

  1. Basic List component:
import { List } from 'react-virtualized';

function VirtualizedList({ items }) {
  return (
    <List
      width={300}
      height={300}
      rowCount={items.length}
      rowHeight={50}
      rowRenderer={({ index, key, style }) => (
        <div key={key} style={style}>
          {items[index]}
        </div>
      )}
    />
  );
}
  1. Grid component with variable column widths:
import { Grid } from 'react-virtualized';

function VariableWidthGrid({ data }) {
  return (
    <Grid
      cellRenderer={({ columnIndex, key, rowIndex, style }) => (
        <div key={key} style={style}>
          {data[rowIndex][columnIndex]}
        </div>
      )}
      columnCount={data[0].length}
      columnWidth={({ index }) => (index % 3 === 0 ? 200 : 100)}
      height={300}
      rowCount={data.length}
      rowHeight={50}
      width={500}
    />
  );
}
  1. AutoSizer component for responsive layouts:
import { AutoSizer, List } from 'react-virtualized';

function ResponsiveList({ items }) {
  return (
    <AutoSizer>
      {({ height, width }) => (
        <List
          height={height}
          rowCount={items.length}
          rowHeight={50}
          rowRenderer={({ index, key, style }) => (
            <div key={key} style={style}>
              {items[index]}
            </div>
          )}
          width={width}
        />
      )}
    </AutoSizer>
  );
}

Getting Started

  1. Install the package:

    npm install react-virtualized
    
  2. Import the desired components:

    import { List, AutoSizer } from 'react-virtualized';
    
  3. Use the components in your React application:

    function MyList({ items }) {
      return (
        <AutoSizer>
          {({ height, width }) => (
            <List
              width={width}
              height={height}
              rowCount={items.length}
              rowHeight={50}
              rowRenderer={({ index, key, style }) => (
                <div key={key} style={style}>
                  {items[index]}
                </div>
              )}
            />
          )}
        </AutoSizer>
      );
    }
    
  4. Don't forget to import the CSS:

    import 'react-virtualized/styles.css';
    

Competitor Comparisons

5,365

🤖 Headless UI for Virtualizing Large Element Lists in JS/TS, React, Solid, Vue and Svelte

Pros of Virtual

  • Framework-agnostic, supporting React, Vue, Solid, and more
  • More flexible API with customizable options for various virtualization scenarios
  • Smaller bundle size and improved performance

Cons of Virtual

  • Steeper learning curve due to more complex API
  • Less mature ecosystem with fewer pre-built components
  • May require more manual configuration for some use cases

Code Comparison

React-virtualized:

import { List } from 'react-virtualized';

<List
  width={300}
  height={300}
  rowCount={1000}
  rowHeight={20}
  rowRenderer={({ index, key, style }) => (
    <div key={key} style={style}>Row {index}</div>
  )}
/>

Virtual:

import { useVirtual } from '@tanstack/react-virtual';

const { virtualItems, totalSize } = useVirtual({
  size: 1000,
  parentRef: parentRef,
  estimateSize: () => 20,
});

<div ref={parentRef} style={{ height: '300px', overflow: 'auto' }}>
  <div style={{ height: `${totalSize}px` }}>
    {virtualItems.map(virtualRow => (
      <div key={virtualRow.index} style={{ height: `${virtualRow.size}px`, transform: `translateY(${virtualRow.start}px)` }}>
        Row {virtualRow.index}
      </div>
    ))}
  </div>
</div>

Both libraries offer efficient virtualization for large lists, but Virtual provides more flexibility at the cost of increased complexity. React-virtualized offers a simpler API with pre-built components, while Virtual allows for more customization across different frameworks.

React components for efficiently rendering large lists and tabular data

Pros of react-window

  • Smaller bundle size (approximately 1/3 the size of react-virtualized)
  • Simpler API with fewer components, making it easier to learn and use
  • Better performance due to reduced overhead and optimized rendering

Cons of react-window

  • Fewer features compared to react-virtualized (e.g., no support for multi-directional scrolling or cell measuring)
  • Less flexibility in customization options
  • Might require additional work to implement some advanced use cases

Code Comparison

react-virtualized:

import { List } from 'react-virtualized';

<List
  width={300}
  height={300}
  rowCount={1000}
  rowHeight={20}
  rowRenderer={({ index, key, style }) => (
    <div key={key} style={style}>
      Row {index}
    </div>
  )}
/>

react-window:

import { FixedSizeList } from 'react-window';

<FixedSizeList
  height={300}
  width={300}
  itemCount={1000}
  itemSize={20}
>
  {({ index, style }) => (
    <div style={style}>Row {index}</div>
  )}
</FixedSizeList>

The code comparison shows that react-window has a slightly simpler API, with fewer props and a more straightforward implementation. However, both libraries achieve similar results in terms of rendering large lists efficiently.

The most powerful virtual list component for React

Pros of react-virtuoso

  • Simpler API with fewer components, making it easier to use and integrate
  • Better support for dynamic content and variable-sized items
  • More frequent updates and active maintenance

Cons of react-virtuoso

  • Less mature and battle-tested compared to react-virtualized
  • Fewer additional features and utilities beyond core virtualization

Code Comparison

react-virtualized:

import { List } from 'react-virtualized';

<List
  width={300}
  height={300}
  rowCount={1000}
  rowHeight={20}
  rowRenderer={({ index, key, style }) => (
    <div key={key} style={style}>Row {index}</div>
  )}
/>

react-virtuoso:

import { Virtuoso } from 'react-virtuoso';

<Virtuoso
  style={{ height: '300px', width: '300px' }}
  totalCount={1000}
  itemContent={index => <div>Row {index}</div>}
/>

Both libraries provide efficient rendering of large lists, but react-virtuoso offers a more straightforward API. react-virtualized requires explicit width, height, and rowHeight props, while react-virtuoso can infer these values in many cases. react-virtuoso's itemContent prop is more flexible than react-virtualized's rowRenderer, especially for variable-sized items.

react-virtualized has been around longer and offers additional components like Grid and Table, which may be beneficial for complex use cases. However, react-virtuoso's simpler API and better support for dynamic content make it an attractive option for many projects, especially those with varying item sizes or frequently changing data.

5,365

🤖 Headless UI for Virtualizing Large Element Lists in JS/TS, React, Solid, Vue and Svelte

Pros of Virtual

  • Framework-agnostic, supporting React, Vue, Solid, and more
  • More flexible API with customizable options for various virtualization scenarios
  • Smaller bundle size and improved performance

Cons of Virtual

  • Steeper learning curve due to more complex API
  • Less mature ecosystem with fewer pre-built components
  • May require more manual configuration for some use cases

Code Comparison

React-virtualized:

import { List } from 'react-virtualized';

<List
  width={300}
  height={300}
  rowCount={1000}
  rowHeight={20}
  rowRenderer={({ index, key, style }) => (
    <div key={key} style={style}>Row {index}</div>
  )}
/>

Virtual:

import { useVirtual } from '@tanstack/react-virtual';

const { virtualItems, totalSize } = useVirtual({
  size: 1000,
  parentRef: parentRef,
  estimateSize: () => 20,
});

<div ref={parentRef} style={{ height: '300px', overflow: 'auto' }}>
  <div style={{ height: `${totalSize}px` }}>
    {virtualItems.map(virtualRow => (
      <div key={virtualRow.index} style={{ height: `${virtualRow.size}px`, transform: `translateY(${virtualRow.start}px)` }}>
        Row {virtualRow.index}
      </div>
    ))}
  </div>
</div>

Both libraries offer efficient virtualization for large lists, but Virtual provides more flexibility at the cost of increased complexity. React-virtualized offers a simpler API with pre-built components, while Virtual allows for more customization across different frameworks.

A tiny but mighty 3kb list virtualization library, with zero dependencies 💪 Supports variable heights/widths, sticky items, scrolling to index, and more!

Pros of react-tiny-virtual-list

  • Lightweight and focused: Smaller bundle size, specifically designed for simple list virtualization
  • Simpler API: Easier to set up and use for basic virtualization needs
  • Better performance for simpler use cases: Optimized for straightforward list rendering

Cons of react-tiny-virtual-list

  • Limited features: Lacks advanced functionalities like grid layouts, scrolling utilities, and cell measuring
  • Less flexibility: May not be suitable for complex virtualization scenarios
  • Smaller community and ecosystem: Fewer resources, plugins, and third-party integrations available

Code Comparison

react-virtualized:

import { List } from 'react-virtualized';

<List
  width={300}
  height={300}
  rowCount={1000}
  rowHeight={20}
  rowRenderer={({ index, style }) => (
    <div style={style}>Row {index}</div>
  )}
/>

react-tiny-virtual-list:

import VirtualList from 'react-tiny-virtual-list';

<VirtualList
  width={300}
  height={300}
  itemCount={1000}
  itemSize={20}
  renderItem={({ index, style }) => (
    <div style={style}>Row {index}</div>
  )}
/>

Both libraries offer similar basic functionality, but react-virtualized provides more advanced features and customization options, while react-tiny-virtual-list focuses on simplicity and lightweight implementation for basic list virtualization needs.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

React virtualized

React components for efficiently rendering large lists and tabular data. Check out the demo for some examples.

If you like this project, 🎉 become a sponsor or ☕ buy me a coffee

Sponsors

The following wonderful companies have sponsored react-virtualized:

Learn more about becoming a sponsor!

A word about react-window

If you're considering adding react-virtualized to a project, take a look at react-window as a possible lighter-weight alternative. Learn more about how the two libraries compare here.

Getting started

Install react-virtualized using npm.

npm install react-virtualized --save

ES6, CommonJS, and UMD builds are available with each distribution. For example:

// Most of react-virtualized's styles are functional (eg position, size).
// Functional styles are applied directly to DOM elements.
// The Table component ships with a few presentational styles as well.
// They are optional, but if you want them you will need to also import the CSS file.
// This only needs to be done once; probably during your application's bootstrapping process.
import 'react-virtualized/styles.css';

// You can import any component you want as a named export from 'react-virtualized', eg
import {Column, Table} from 'react-virtualized';

// But if you only use a few react-virtualized components,
// And you're concerned about increasing your application's bundle size,
// You can directly import only the components you need, like so:
import AutoSizer from 'react-virtualized/dist/commonjs/AutoSizer';
import List from 'react-virtualized/dist/commonjs/List';

Note webpack 4 makes this optimization itself, see the documentation.

If the above syntax looks too cumbersome, or you import react-virtualized components from a lot of places, you can also configure a Webpack alias. For example:

// Partial webpack.config.js
{
  alias: {
    'react-virtualized/List': 'react-virtualized/dist/es/List',
  },
  ...rest
}

Then you can just import like so:

import List from 'react-virtualized/List';

// Now you can use <List {...props} />

You can also use a global-friendly UMD build:

<link rel="stylesheet" href="path-to-react-virtualized/styles.css" />
<script src="path-to-react-virtualized/dist/umd/react-virtualized.js"></script>

Now you're ready to start using the components. You can learn more about which components react-virtualized has to offer below.

Dependencies

React Virtualized has very few dependencies and most are managed by NPM automatically. However the following peer dependencies must be specified by your project in order to avoid version conflicts: react, react-dom. NPM will not automatically install these for you but it will show you a warning message with instructions on how to install them.

Pure Components

By default all react-virtualized components use shallowCompare to avoid re-rendering unless props or state has changed. This occasionally confuses users when a collection's data changes (eg ['a','b','c'] => ['d','e','f']) but props do not (eg array.length).

The solution to this is to let react-virtualized know that something external has changed. This can be done a couple of different ways.

Pass-thru props

The shallowCompare method will detect changes to any props, even if they aren't declared as propTypes. This means you can also pass through additional properties that affect cell rendering to ensure changes are detected. For example, if you're using List to render a list of items that may be re-sorted after initial render- react-virtualized would not normally detect the sort operation because none of the properties it deals with change. However you can pass through the additional sort property to trigger a re-render. For example:

<List {...listProps} sortBy={sortBy} />
Public methods

Grid and Collection components can be forcefully re-rendered using forceUpdate. For Table and List, you'll need to call forceUpdateGrid to ensure that the inner Grid is also updated. For MultiGrid, you'll need to call forceUpdateGrids to ensure that the inner Grids are updated.

Documentation

API documentation available here.

There are also a couple of how-to guides:

Examples

Examples for each component can be seen in the documentation.

Here are some online demos of each component:

And here are some "recipe" type demos:

Supported Browsers

react-virtualized aims to support all evergreen browsers and recent mobile browsers for iOS and Android. IE 9+ is also supported (although IE 9 will require some user-defined, custom CSS since flexbox layout is not supported).

If you find a browser-specific problem, please report it along with a repro case. The easiest way to do this is probably by forking this Plunker.

Friends

Here are some great components built on top of react-virtualized:

  • react-infinite-calendar: Infinite scrolling date-picker with localization, themes, keyboard support, and more
  • react-sortable-hoc: Higher-order components to turn any list into an animated, touch-friendly, sortable list
  • react-sortable-tree: Drag-and-drop sortable representation of hierarchical data
  • react-virtualized-checkbox: Checkbox group component with virtualization for large number of options
  • react-virtualized-select: Drop-down menu for React with windowing to support large numbers of options.
  • react-virtualized-tree: A reactive tree component that aims to render large sets of tree structured data in an elegant and performant way
  • react-timeline-9000: A calendar timeline component that is capable of displaying and interacting with a large number of items

Contributions

Use GitHub issues for requests.

I actively welcome pull requests; learn how to contribute.

Changelog

Changes are tracked in the changelog.

License

react-virtualized is available under the MIT License.

NPM DownloadsLast 30 Days