A tiny but mighty list virtualization library, with zero dependencies 💪
- Tiny & dependency free – Only 3kb gzipped
- Render millions of items, without breaking a sweat
- Scroll to index or set the initial scroll offset
- Supports fixed or variable heights/widths
- Vertical or Horizontal lists
npm install react-tiny-virtual-list --save
ES6, CommonJS, and UMD builds are available with each distribution. For example:
You can also use a global-friendly UMD build:
;;;const data = 'A' 'B' 'C' 'D' 'E' 'F' ...;;
|width||Number | String*||✓||Width of List. This property will determine the number of rendered items when scrollDirection is
|height||Number | String*||✓||Height of List. This property will determine the number of rendered items when scrollDirection is
|itemCount||Number||✓||The number of items you want to render|
|renderItem||Function||✓||Responsible for rendering an item given it's index:
|itemSize||✓||Either a fixed height/width (depending on the scrollDirection), an array containing the heights of all the items in your list, or a function that returns the height of an item given its index:
|scrollDirection||String||Whether the list should scroll vertically or horizontally. One of
|scrollOffset||Number||Can be used to control the scroll offset; Also useful for setting an initial scroll offset|
|scrollToIndex||Number||Item index to scroll to (by forcefully scrolling if necessary) x|
|scrollToAlignment||String||Used in combination with
|stickyIndices||Number||An array of indexes (eg.
|overscanCount||Number||Number of extra buffer items to render above/below the visible items. Tweaking this can help reduce scroll flickering on certain browsers/devices.|
|estimatedItemSize||Number||Used to estimate the total size of the list before all of its items have actually been measured. The estimated total height is progressively adjusted as items are rendered.|
|onItemsRendered||Function||Callback invoked with information about the slice of rows/columns that were just rendered. It has the following signature:
|onScroll||Function||Callback invoked whenever the scroll offset changes within the inner scrollable region. It has the following signature:
* Width may only be a string when
'vertical'. Similarly, Height may only be a string if
recomputeSizes (index: number)
This method force recomputes the item sizes after the specified index (these are normally cached).
VirtualList has no way of knowing when its underlying data has changed, since it only receives a itemSize property. If the itemSize is a
number, this isn't an issue, as it can compare before and after values and automatically call
However, if you're passing a function to
itemSize, that type of comparison is error prone. In that event, you'll need to call
recomputeSizes manually to inform the
VirtualList that the size of its items has changed.
Common Issues with PureComponent
react-tiny-virtual-list uses PureComponent, so it only updates when it's props change. Therefore, if only the order of your data changes (eg
react-tiny-virtual-list has no way to know your data has changed and that it needs to re-render.
You can force it to re-render by calling forceUpdate on it or by passing it an extra prop that will change every time your data changes.
Found an issue? Please report it along with any relevant details to reproduce it. If you can, please provide a live demo replicating the issue you're describing. You can fork this Code Sandbox as a starting point.
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.