A tiny but mighty 2kb list virtualization component, with zero dependencies 💪
- Tiny & dependency free – 5kb minified, ~2kb gzipped
- Render millions of rows, without breaking a sweat
- Scroll to index or set the initial scroll offset
- Supports fixed or variable row heights
Using npm:
npm install react-tiny-virtual-list --save
ES6, CommonJS, and UMD builds are available with each distribution. For example:
import VirtualList from 'react-tiny-virtual-list';
You can also use a global-friendly UMD build:
<script src="react-tiny-virtual-list/umd/react-tiny-virtual-list.js"></script>
<script>
var VirtualList = window.VirtualList.default;
...
</script>
import React from 'react';
import {render} from 'react-dom';
import VirtualList from 'react-tiny-virtual-list';
const data = ['A', 'B', 'C', 'D', 'E', 'F', ...];
render(
<VirtualList
height={600}
rowCount={data.length}
rowHeight={50} // Also supports variable heights (array or function getter)
renderRow={({index, style}) =>
<div key={index} style={style}> // The style property contains the row's absolute position
Letter: {data[index]}, Row: #{index}
</div>
}
/>,
document.getElementById('root')
);
Property | Type | Required? | Description |
---|---|---|---|
width | Number or String | Width of List. Defaults to 100% |
|
height | Number | ✓ | Height of List; this property will determine the number of rendered vs virtualized rows. |
rowCount | Number | ✓ | The number of rows you want to render |
renderRow | Function | ✓ | Responsible for rendering a row: ({index: number, style: Object}): React.PropTypes.node . The returned element must handle key and style. |
rowHeight | ✓ | Either a fixed row height (number), an array containing the heights of all the rows in your list, or a function that returns the height of a row given its index: (index: number): number |
|
scrollTop | Number | Can be used to control the vertical scroll offset; Useful for setting an initial scroll offset | |
scrollToIndex | Number | Row index to ensure visible (by forcefully scrolling if necessary) | |
scrollToAlignment | Used in combination with scrollToIndex , this prop controls the alignment of the scrolled to row. One of: 'auto', 'start', 'center' or 'end' |
||
overscanCount | Number | Number of extra buffer rows to render above/below the visible rows. Tweaking this can help reduce scroll flickering on certain browers/devices. | |
estimatedRowHeight | Number | Used to estimate the total height of the list before all of its rows have actually been measured. The estimated total height is progressively adjusted as rows are rendered. |
Found an issue? Please report it along with any relevant details to reproduce it.
Feature requests / pull requests are welcome, though please take a moment to make sure your contributions fits within the scope of the project. Learn how to contribute
This library draws inspiration from react-virtualized, and is meant as a bare-minimum replacement for the List component. If you're looking for a tiny, lightweight and dependency-free list virtualization library that supports variable heights, you're in the right place! If you're looking for something that supports more use-cases, I highly encourage you to check out react-virtualized instead, it's a fantastic library ❤️
react-tiny-virtual-list is available under the MIT License.