react-infinite vs react-list vs react-tiny-virtual-list vs react-virtualized vs react-window
React Virtualization and Infinite Scrolling Libraries
react-infinitereact-listreact-tiny-virtual-listreact-virtualizedreact-windowSimilar Packages:

React Virtualization and Infinite Scrolling Libraries

React Virtualization and Infinite Scrolling Libraries are tools that help render large lists or grids of items efficiently in React applications. These libraries use techniques like virtualization, which only renders the items currently visible in the viewport, and infinite scrolling, which loads more items as the user scrolls down. This approach significantly improves performance and reduces memory usage, making it ideal for applications with long lists or data-heavy interfaces. Popular libraries in this space include react-virtualized, react-window, and react-infinite, each offering unique features and optimizations for handling large datasets in a React-friendly way.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
react-infinite02,687243 kB102-BSD-3-Clause
react-list01,97434.9 kB71a year agoMIT
react-tiny-virtual-list02,497-548 years agoMIT
react-virtualized027,0802.24 MB1a year agoMIT
react-window017,113209 kB125 days agoMIT

Feature Comparison: react-infinite vs react-list vs react-tiny-virtual-list vs react-virtualized vs react-window

Virtualization Technique

  • react-infinite:

    react-infinite implements infinite scrolling by loading more items as the user scrolls down. It does not use virtualization, which means all items are rendered in the DOM, but it efficiently manages the loading of additional items to create a seamless scrolling experience.

  • react-list:

    react-list supports virtualization by rendering only the visible items in the list, which reduces the number of DOM nodes and improves performance. It can handle dynamic item heights, making it versatile for lists with varying content sizes.

  • react-tiny-virtual-list:

    react-tiny-virtual-list uses virtualization to render only the items that are currently visible in the viewport. It is designed to be lightweight and efficient, minimizing the number of rendered items to improve performance, especially in large lists.

  • react-virtualized:

    react-virtualized provides a comprehensive set of components for virtualization, including support for fixed and dynamic heights, grids, and tables. It is highly customizable and can handle complex layouts, making it suitable for a wide range of applications that require advanced virtualization techniques.

  • react-window:

    react-window is a lightweight library for virtualization that focuses on simplicity and performance. It renders only the visible items in a list or grid, reducing the number of DOM nodes and improving rendering speed. It is designed to be easy to use while providing efficient virtualization for large datasets.

Bundle Size

  • react-infinite:

    react-infinite has a moderate bundle size, but it is not optimized for virtualization, which means it may not be the best choice for performance-sensitive applications with extremely large lists.

  • react-list:

    react-list is a lightweight library that adds minimal overhead to your bundle. It is designed to be efficient while providing the necessary features for virtualization and dynamic item rendering.

  • react-tiny-virtual-list:

    react-tiny-virtual-list is designed to be ultra-lightweight, making it an excellent choice for projects where bundle size is a critical concern. Its minimalistic design ensures that you get virtualization without adding unnecessary weight to your application.

  • react-virtualized:

    react-virtualized is a feature-rich library, which means it comes with a larger bundle size compared to simpler solutions. However, the trade-off is worth it for applications that need advanced virtualization features and customization options.

  • react-window:

    react-window is a much smaller and more efficient alternative to react-virtualized, offering similar virtualization capabilities with a significantly reduced bundle size. This makes it ideal for modern applications that prioritize performance and quick load times.

Dynamic Item Heights

  • react-infinite:

    react-infinite does not handle dynamic item heights natively, as it focuses on infinite scrolling rather than virtualization. This can be a limitation if your list items have varying heights and you need precise rendering.

  • react-list:

    react-list supports dynamic item heights, allowing it to handle lists where items may have different sizes. This feature makes it more flexible and suitable for a wider range of use cases, including lists with images, text, or other variable content.

  • react-tiny-virtual-list:

    react-tiny-virtual-list supports dynamic item heights, but it requires you to provide a function that calculates the height of each item. This allows it to accurately render items with varying heights while still benefiting from virtualization.

  • react-virtualized:

    react-virtualized provides robust support for dynamic item heights, allowing you to create lists and grids where items can have different sizes. It includes components that can handle both fixed and variable heights, making it highly versatile for complex layouts.

  • react-window:

    react-window supports dynamic item heights, but like react-tiny-virtual-list, it requires you to provide a way to calculate the height of each item. This feature allows it to efficiently render lists with varying item sizes while keeping the virtualization performance intact.

Ease of Integration: Code Examples

  • react-infinite:

    Integrating react-infinite is straightforward, especially for simple lists. Its API is easy to understand, and it requires minimal setup to get infinite scrolling working. However, it may require additional work to handle loading states and data fetching. Example:

    import React from 'react';
    import Infinite from 'react-infinite';
    
    const InfiniteList = ({ items, loadMore }) => {
      return (
        <Infinite
          elementHeight={50}
          infiniteLoadBeginEdgeOffset={100}
          onInfiniteLoad={loadMore}
          isInfiniteLoading={false}
        >
          {items.map(item => (
            <div key={item.id}>{item.content}</div>
          ))}
        </Infinite>
      );
    };
    
  • react-list:

    react-list is easy to integrate into existing projects, especially if you need a quick solution for lists with varying heights. Its API is simple, and it works well with both static and dynamic data. Example:

    import React from 'react';
    import { List } from 'react-list';
    
    const MyList = ({ items }) => {
      return (
        <List
          itemRenderer={(index, key) => <div key={key}>{items[index]}</div>}
          length={items.length}
          type="uniform"
        />
      );
    };
    
  • react-tiny-virtual-list:

    Integrating react-tiny-virtual-list is quick and easy, thanks to its simple API and minimal configuration requirements. It is particularly well-suited for projects that need virtualization without a lot of complexity. Example:

    import React from 'react';
    import { VirtualList } from 'react-tiny-virtual-list';
    
    const MyVirtualList = ({ items }) => {
      return (
        <VirtualList
          width={300}
          height={400}
          itemCount={items.length}
          itemSize={50}
          overscanCount={5}
          itemRenderer={({ index, style }) => (
            <div style={style}>{items[index]}</div>
          )}
        />
      );
    };
    
  • react-virtualized:

    react-virtualized may require more time to integrate due to its complexity and the wide range of features it offers. However, it is well-documented, and once you understand its components, it provides great flexibility and performance. Example:

    import React from 'react';
    import { List } from 'react-virtualized';
    
    const MyVirtualizedList = ({ items }) => {
      return (
        <List
          width={300}
          height={400}
          rowCount={items.length}
          rowHeight={50}
          rowRenderer={({ index, style }) => (
            <div style={style}>{items[index]}</div>
          )}
        />
      );
    };
    
  • react-window:

    react-window is designed for easy integration, with a straightforward API that makes it simple to implement virtualization in your lists. It is well-suited for developers who want a quick and efficient solution without a steep learning curve. Example:

    import React from 'react';
    import { FixedSizeList } from 'react-window';
    
    const MyWindowedList = ({ items }) => {
      return (
        <FixedSizeList
          height={400}
          itemCount={items.length}
          itemSize={50}
          width={300}
        >
          {({ index, style }) => (
            <div style={style}>{items[index]}</div>
          )}
        </FixedSizeList>
      );
    };
    

How to Choose: react-infinite vs react-list vs react-tiny-virtual-list vs react-virtualized vs react-window

  • react-infinite:

    Choose react-infinite if you need a simple solution for infinite scrolling with support for loading more items as the user scrolls. It is easy to integrate and works well for lists where you can fetch data in chunks.

  • react-list:

    Select react-list if you want a lightweight library that supports both virtualization and dynamic item heights. It is ideal for lists where items may have varying heights, and you need a flexible solution without a lot of overhead.

  • react-tiny-virtual-list:

    Opt for react-tiny-virtual-list if you need a minimalistic and highly performant virtualized list component. It is designed for simplicity and efficiency, making it a great choice for projects where you want to keep the bundle size small while still benefiting from virtualization.

  • react-virtualized:

    Choose react-virtualized if you need a comprehensive solution with a wide range of features for virtualizing lists, tables, and grids. It is highly customizable and suitable for complex applications that require advanced virtualization techniques and support for both fixed and dynamic item sizes.

  • react-window:

    Select react-window if you want a lightweight and modern alternative to react-virtualized with a simpler API. It is designed for performance and ease of use, making it a great choice for projects that need efficient virtualization without the complexity of a larger library.

README for react-infinite

React Infinite

Build Status Coverage Status npm version bitHound Score

A browser-ready efficient scrolling container based on UITableView.

React Infinite 0.7.1 only supports React 0.14 and above. Please pin your package to 0.6.0 for React 0.13 support.

When a long list of DOM elements are placed in a scrollable container, all of them are kept in the DOM even when they are out the user's view. This is highly inefficient, especially in cases when scrolling lists can be tens or hundreds of thousands of items long. React Infinite solves this by rendering only DOM nodes that the user is able to see or might soon see. Other DOM nodes are clustered and rendered as a single blank node.

Installation

In the Browser

The relevant files are dist/react-infinite.js and dist/react-infinite.min.js. You must have React available as a global variable named React on the window. Including either file, through concatenation or a script tag, will produce a global variable named Infinite representing the component.

In NPM

React Infinite uses a Universal Module Definition so you can use it in NPM as well. npm install this package and

var Infinite = require('react-infinite');

In Browserify

If you want to use the source with Browserify, the ES5-compiled source is directly requirable from the /build folder off NPM.

Otherwise, you can follow the instructions for NPM.

Basic Use

Elements of Equal Height

To use React Infinite with a list of elements you want to make scrollable, provide them to React Infinite as children.

<Infinite containerHeight={200} elementHeight={40}>
    <div className="one"/>
    <div className="two"/>
    <div className="three"/>
</Infinite>

Elements of Varying Heights

If not all of the children have the same height, you must provide an array of integers to the elementHeight prop instead.

<Infinite containerHeight={200} elementHeight={[111, 252, 143]}>
    <div className="111-px"/>
    <div className="252-px"/>
    <div className="143-px"/>
</Infinite>

Using the Window to Scroll (useWindowAsScrollContainer mode)

To use the entire window as a scroll container instead of just a single div (thus using window.scrollY instead of a DOM element's scrollTop), add the useWindowAsScrollContainer prop.

<Infinite containerHeight={200} elementHeight={[111, 252, 143]}
          useWindowAsScrollContainer>
    <div className="111-px"/>
    <div className="252-px"/>
    <div className="143-px"/>
</Infinite>

As A Chat or Message Box (displayBottomUpwards mode)

React Infinite now supports being used as a chat box, i.e. appended elements appear at the bottom when added, and the loading of the next page occurs when the user scrolls to the top of the container. To do so, simply add the displayBottomUpwards prop. A sample implementation can be consulted for more information - run gulp develop to compile the example files.

<Infinite containerHeight={200} elementHeight={[111, 252, 143]}
          displayBottomUpwards>
    // insert messages for subsequent pages at this point
    <div className="third-latest-chat"/>
    <div className="second-latest-chat"/>
    <div className="latest-chat-message"/>
</Infinite>

Note on Smooth Scrolling

A wrapper div is applied that disables pointer events on the children for a default of 150 milliseconds after the last user scroll action for browsers with inertial scrolling. To configure this, set timeScrollStateLastsForAfterUserScrolls.

Static Methods

Function Infinite.containerHeightScaleFactor(Number number)

This function allows a value to be specified for preloadBatchSize and preloadAdditionalHeight that is a relative to the container height. Please see the documentation for those two configuration options for further information on how to use it.

Configuration Options

Children

The children of the <Infinite> element are the components you want to render. This gives you as much flexibility as you need in the presentation of those components. Each child can be a different component if you desire. If you wish to render a set of children not all of which have the same height, you must map each component in the children array to an number representing its height and pass it in as the elementHeight prop.

Major Display Modes

By default, React Infinite renders a single element with the provided containerHeight, and the list sticks to the top like a regular table. However, you can choose to use the entire window as the scroll container or make React Infinite like a chatbox with the following options. They can be used together if you wish.

Bool useWindowAsScrollContainer

Defaults to false. This option allows the window to be used as the scroll container, instead of an arbitrary div, when it is set to true. This means that scroll position is detected by window.scrollY instead of the scrollTop of the div that React Infinite creates. Using this option is a way of achieving smoother scrolling on mobile before the problem is solved for container divs.

Bool displayBottomUpwards

Defaults to false. This allows React Infinite to be used as a chatbox. This means that the scroll is stuck to the bottom by default, and the user scrolls up to the top of the container to load the next page. The children are displayed in the same order.

Configuration Options

(Required) Number | [Number] elementHeight

If each child element has the same height, you can pass a number representing that height as the elementHeight prop. If the children do not all have the same height, you can pass an array which is a map the children to numbers representing their heights to the elementHeight prop.

Number containerHeight

The height of the scrolling container in pixels. This is a required prop if useWindowAsScrollContainer is not set to true.

Number | Object preloadBatchSize

Defaults to this.props.containerHeight * 0.5. Imagine the total height of the scrollable divs. Now divide this equally into blocks preloadBatchSize pixels high. Every time the container's scrollTop enters each of these blocks the set of elements rendered in full are those contained within the block and elements that are within preloadAdditionalHeight above and below it.

When working with the window as the scroll container, it is sometimes useful to specify a scale factor relative to the container height as the batch size, so your code does not need to know anything about the window. To do this, use Infinite.containerHeightScaleFactor. So, for example, if you want the preloaded batch size to be twice the container height, write preloadBatchSize={Infinite.containerHeightScaleFactor(2)}.

Number | Object preloadAdditionalHeight

Defaults to this.props.containerHeight. The total height of the area in which elements are rendered in full is height of the current scroll block (see preloadBatchSize) as well as preloadAdditionalHeight above and below it.

When working with the window as the scroll container, it is sometimes useful to specify this relative to the container height. If you want the preloaded additional height to be twice the container height, write preloadAdditionalHeight={Infinite.containerHeightScaleFactor(2)}. Please see preloadBatchSize for more details.

Function handleScroll(DOMNode node)

Defaults to function(){}. A function that is called when the container is scrolled, i.e. when the onScroll event of the infinite scrolling container is fired. The only argument passed to it is the native DOM Node of the scrolling container.

Number infiniteLoadBeginEdgeOffset

Defaults to undefined, which means that infinite loading is disabled. To disable infinite loading, do not provide this property or set it to undefined.

Regular Mode When the user reaches this number of pixels from the bottom, the infinite load sequence will be triggered by showing the infinite load spinner delegate and calling the function onInfiniteLoad.

displayBottomUpwards mode When the user reaches this number of pixels from the top of the container, the infinite load sequence will be triggered by showing the infinite loading spinner delegate at the top of the container and calling onInfiniteLoad.

Function onInfiniteLoad()

Defaults to function(){}. This function is called when the scroll exceeds infiniteLoadBeginEdgeOffset. Before this function is called, the infinite loading spinner is automatically turned on. You can set up infinite scrolling with this function like this:

  1. Fetch a new page of records from the appropriate API
  2. When the AJAX call returns, send the new list of elements (with the items that were just fetched) back as the children of React Infinite.
  3. Set React Infinite's isInfiniteLoading prop to false to hide the loading spinner display

onInfiniteLoad relies heavily on passing props as a means of communication in the style of idiomatic React.

React Node loadingSpinnerDelegate

Defaults to <div/>. The element that is provided is used to render the loading view when React Infinite's isInfiniteLoading property is set to true. A React Node is anything that satisfies React.PropTypes.node.

Bool isInfiniteLoading

Defaults to false. This property determines whether the infinite spinner is showing.

Number timeScrollStateLastsForAfterUserScrolls

Defaults to 150 (in milliseconds). On Apple and some other devices, scroll is inertial. This means that the window continues to scroll for several hundred milliseconds after an onScroll event is fired. To prevent janky behavior, we do not want pointer-events to reactivate before the window has finished moving. Setting this parameter causes the Infinite component to think that the user is still scrolling for the specified number of milliseconds after the last onScroll event is received.

String className

Allows a CSS class to be set on the scrollable container.

Sample Code

Code samples are now available in the /examples directory for your perusal. Two examples are provided, one for constant height with infinite loading and another with random variable heights with infinite loading. To generate the files necessary for the examples, execute npm install && gulp build -E. You may need to first install gulp with npm install -g gulp.

To get you started, here is some sample code that implements an infinite scroll with an simulated delay of 2.5 seconds. A live demo of this example is available on our blog.

var createReactClass = require('create-react-class');

var ListItem = createReactClass({
    render: function() {
        return <div className="infinite-list-item">
        List Item {this.props.num}
        </div>;
    }
});

var InfiniteList = createReactClass({
    getInitialState: function() {
        return {
            elements: this.buildElements(0, 20),
            isInfiniteLoading: false
        }
    },

    buildElements: function(start, end) {
        var elements = [];
        for (var i = start; i < end; i++) {
            elements.push(<ListItem key={i} num={i}/>)
        }
        return elements;
    },

    handleInfiniteLoad: function() {
        var that = this;
        this.setState({
            isInfiniteLoading: true
        });
        setTimeout(function() {
            var elemLength = that.state.elements.length,
                newElements = that.buildElements(elemLength, elemLength + 1000);
            that.setState({
                isInfiniteLoading: false,
                elements: that.state.elements.concat(newElements)
            });
        }, 2500);
    },

    elementInfiniteLoad: function() {
        return <div className="infinite-list-item">
            Loading...
        </div>;
    },

    render: function() {
        return <Infinite elementHeight={40}
                         containerHeight={250}
                         infiniteLoadBeginEdgeOffset={200}
                         onInfiniteLoad={this.handleInfiniteLoad}
                         loadingSpinnerDelegate={this.elementInfiniteLoad()}
                         isInfiniteLoading={this.state.isInfiniteLoading}
                         >
            {this.state.elements}
        </Infinite>;
    }
});

ReactDOM.render(<InfiniteList/>, document.getElementById('react-example-one'));

SeatGeek also currently uses React Infinite in production on our event pages; because we only have pages for events in the future, a link would not be appropriate. To see one, head to one of our team pages for the New York Giants, or the New York Mets, or the New York Knicks, and click on the green button for an event to see them in action in the Omnibox.

Contributing to React Infinite

Useful notes for how to contribute are available.