React components for efficiently rendering large lists and tabular data.
This maintained fork publishes the classic react-virtualized API as
@opensourceframework/react-virtualized for projects that need compatibility with the original
component surface.
Check out the original demo for some examples.
react-window is a lighter-weight library by the same
original author. It can be a good fit for new projects with simpler virtualization needs, but it is
not a drop-in replacement for react-virtualized. Use this package when you need the established
react-virtualized components, APIs, and migration surface.
Install @opensourceframework/react-virtualized using your package manager.
npm install @opensourceframework/react-virtualized --save
# or
pnpm add @opensourceframework/react-virtualizedES6, 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 '@opensourceframework/react-virtualized/styles.css';
// You can import any component you want as a named export from '@opensourceframework/react-virtualized', eg
import { Column, Table } from '@opensourceframework/react-virtualized';Note webpack 4 makes this optimization itself, see the documentation.
Named exports are the supported import style for this scoped package. The published package ships a
single bundled entry point, so do not copy old examples that import from
react-virtualized/dist/commonjs/* or other unscoped subpaths.
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.
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.
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.
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} />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.
API documentation available here.
There are also a couple of how-to guides:
- Customizing classes and styles
- Displaying items in reverse order
- Using AutoSizer
- Creating an infinite-loading list
- Natural sort Table
- Sorting a Table by multiple columns
Examples for each component can be seen in the documentation.
Here are some online demos of each component:
- ArrowKeyStepper
- AutoSizer
- CellMeasurer
- Collection
- ColumnSizer
- Grid
- InfiniteLoader
- List
- Masonry
- MultiGrid
- ScrollSync
- Table
- WindowScroller
And here are some "recipe" type demos:
- Table with resizable (drag and drop) columns
- Collapsable tree view
- Full-page grid (spreadsheet)
- Dynamic cell measuring
- Cell hover effects
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.
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
Use OpenSource Framework issues for requests.
Pull requests are welcome in the OpenSource Framework monorepo.
Changes are tracked in the package changelog.
react-virtualized is available under the MIT License.
This package is part of the OpenSource Framework monorepo.
Maintained by @opensourceframework in the monorepo.
