react-infinite-scroll-component vs react-list vs react-virtualized vs react-window
Reactのスクロールライブラリ
react-infinite-scroll-componentreact-listreact-virtualizedreact-window類似パッケージ:

Reactのスクロールライブラリ

これらのライブラリは、Reactアプリケーションにおけるスクロール機能を効率的に実装するためのツールです。無限スクロールや大規模なリストの表示を最適化し、パフォーマンスを向上させることができます。特に、データが大量にある場合に、ユーザー体験を損なうことなくスムーズな操作を実現します。

npmのダウンロードトレンド

3 年

GitHub Starsランキング

統計詳細

パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
react-infinite-scroll-component03,068199 kB2021日前MIT
react-list01,97434.9 kB711年前MIT
react-virtualized027,0722.24 MB01年前MIT
react-window017,144209 kB12ヶ月前MIT

機能比較: react-infinite-scroll-component vs react-list vs react-virtualized vs react-window

パフォーマンス最適化

  • react-infinite-scroll-component:

    無限スクロールの実装に特化しており、ユーザーがスクロールするたびに新しいデータを効率的にロードします。これにより、初期ロード時のデータ量を減らし、パフォーマンスを向上させます。

  • react-list:

    アイテムの高さが均一である場合に、リストのレンダリングを最適化します。必要なアイテムのみを描画することで、メモリ使用量を削減し、パフォーマンスを向上させます。

  • react-virtualized:

    仮想化技術を使用して、表示されているアイテムのみをレンダリングします。これにより、大規模なデータセットでもスムーズなスクロールを実現します。

  • react-window:

    軽量な仮想化ライブラリで、必要なアイテムのみを描画します。シンプルなAPIで、パフォーマンスを重視したアプリケーションに適しています。

使いやすさ

  • react-infinite-scroll-component:

    シンプルなAPIを提供しており、無限スクロールの実装が容易です。特別な設定なしで、すぐに使い始めることができます。

  • react-list:

    基本的なリスト表示に特化しているため、使いやすく、簡単に実装できます。特に、アイテムの高さが均一な場合に効果を発揮します。

  • react-virtualized:

    多機能である一方、設定が複雑になることがありますが、ドキュメントが充実しており、学習コストを軽減できます。

  • react-window:

    非常にシンプルなAPIを持ち、すぐに使えるため、初心者にも適しています。必要な機能だけを提供するため、学習曲線が緩やかです。

機能の柔軟性

  • react-infinite-scroll-component:

    無限スクロールの機能を持ち、カスタマイズ可能なローディングインジケーターをサポートしています。

  • react-list:

    リストの表示に特化しており、シンプルな構造でカスタマイズが容易です。

  • react-virtualized:

    リスト、テーブル、グリッドなど、さまざまなコンポーネントを提供し、柔軟なデータ表示が可能です。

  • react-window:

    必要最低限の機能を提供し、簡単にカスタマイズできます。特に、パフォーマンスを重視したアプリケーションに最適です。

メンテナンス性

  • react-infinite-scroll-component:

    シンプルな設計により、メンテナンスが容易です。無限スクロールの実装が簡単で、コードの可読性が高いです。

  • react-list:

    コードがシンプルで、リストの表示に特化しているため、メンテナンスが容易です。

  • react-virtualized:

    多機能であるため、複雑な実装になることがありますが、ドキュメントが充実しており、メンテナンスがしやすいです。

  • react-window:

    軽量でシンプルな設計により、メンテナンスが容易で、必要な機能だけを提供します。

学習曲線

  • react-infinite-scroll-component:

    シンプルなAPIを持ち、すぐに使い始めることができるため、学習曲線は緩やかです。

  • react-list:

    基本的なリスト表示に特化しているため、学習が容易です。

  • react-virtualized:

    多機能であるため、学習曲線はやや急ですが、ドキュメントが充実しているため、習得しやすいです。

  • react-window:

    非常にシンプルなAPIを持ち、学習曲線が緩やかで、初心者にも適しています。

選び方: react-infinite-scroll-component vs react-list vs react-virtualized vs react-window

  • react-infinite-scroll-component:

    無限スクロールを簡単に実装したい場合に最適です。シンプルなAPIで、スクロール位置に応じてデータを動的にロードすることができます。

  • react-list:

    リストの表示が主な目的で、パフォーマンスを重視する場合に適しています。特に、アイテムの高さが均一である場合に効果的です。

  • react-virtualized:

    大規模なデータセットを扱う場合に最適です。リスト、テーブル、グリッドなど、さまざまなコンポーネントを提供し、仮想化によってパフォーマンスを向上させます。

  • react-window:

    軽量でシンプルな仮想化ライブラリを求める場合に適しています。特に、少量の機能で十分な場合や、パフォーマンスを重視する場合におすすめです。

react-infinite-scroll-component のREADME

react-infinite-scroll-component npm npm

All Contributors

A component to make all your infinite scrolling woes go away with just 4.15 kB! Pull Down to Refresh feature added. An infinite-scroll that actually works and super-simple to integrate!

Install

  npm install --save react-infinite-scroll-component

  or

  yarn add react-infinite-scroll-component

  // in code ES6
  import InfiniteScroll from 'react-infinite-scroll-component';
  // or commonjs
  var InfiniteScroll = require('react-infinite-scroll-component');

Using

<InfiniteScroll
  dataLength={items.length} //This is important field to render the next data
  next={fetchData}
  hasMore={true}
  loader={<h4>Loading...</h4>}
  endMessage={
    <p style={{ textAlign: 'center' }}>
      <b>Yay! You have seen it all</b>
    </p>
  }
  // below props only if you need pull down functionality
  refreshFunction={this.refresh}
  pullDownToRefresh
  pullDownToRefreshThreshold={50}
  pullDownToRefreshContent={
    <h3 style={{ textAlign: 'center' }}>&#8595; Pull down to refresh</h3>
  }
  releaseToRefreshContent={
    <h3 style={{ textAlign: 'center' }}>&#8593; Release to refresh</h3>
  }
>
  {items}
</InfiniteScroll>

Using scroll on top

<div
  id="scrollableDiv"
  style={{
    height: 300,
    overflow: 'auto',
    display: 'flex',
    flexDirection: 'column-reverse',
  }}
>
  {/*Put the scroll bar always on the bottom*/}
  <InfiniteScroll
    dataLength={this.state.items.length}
    next={this.fetchMoreData}
    style={{ display: 'flex', flexDirection: 'column-reverse' }} //To put endMessage and loader to the top.
    inverse={true} //
    hasMore={true}
    loader={<h4>Loading...</h4>}
    scrollableTarget="scrollableDiv"
  >
    {this.state.items.map((_, index) => (
      <div style={style} key={index}>
        div - #{index}
      </div>
    ))}
  </InfiniteScroll>
</div>

The InfiniteScroll component can be used in three ways.

  • Specify a value for the height prop if you want your scrollable content to have a specific height, providing scrollbars for scrolling your content and fetching more data.
  • If your scrollable content is being rendered within a parent element that is already providing overflow scrollbars, you can set the scrollableTarget prop to reference the DOM element and use it's scrollbars for fetching more data.
  • Without setting either the height or scrollableTarget props, the scroll will happen at document.body like Facebook's timeline scroll.

docs version wise

3.0.2

live examples

  • infinite scroll (never ending) example using react (body/window scroll)
    • Edit yk7637p62z
  • infinte scroll till 500 elements (body/window scroll)
    • Edit 439v8rmqm0
  • infinite scroll in an element (div of height 400px)
    • Edit w3w89k7x8
  • infinite scroll with scrollableTarget (a parent element which is scrollable)
    • Edit r7rp40n0zm

props

nametypedescription
nextfunctiona function which must be called after reaching the bottom. It must trigger some sort of action which fetches the next data. The data is passed as children to the InfiniteScroll component and the data should contain previous items too. e.g. Initial data = [1, 2, 3] and then next load of data should be [1, 2, 3, 4, 5, 6].
hasMorebooleanit tells the InfiniteScroll component on whether to call next function on reaching the bottom and shows an endMessage to the user
childrennode (list)the data items which you need to scroll.
dataLengthnumberset the length of the data.This will unlock the subsequent calls to next.
loadernodeyou can send a loader component to show while the component waits for the next load of data. e.g. <h3>Loading...</h3> or any fancy loader element
scrollThresholdnumber | stringA threshold value defining when InfiniteScroll will call next. Default value is 0.8. It means the next will be called when user comes below 80% of the total height. If you pass threshold in pixels (scrollThreshold="200px"), next will be called once you scroll at least (100% - scrollThreshold) pixels down.
onScrollfunctiona function that will listen to the scroll event on the scrolling container. Note that the scroll event is throttled, so you may not receive as many events as you would expect.
endMessagenodethis message is shown to the user when he has seen all the records which means he's at the bottom and hasMore is false
classNamestringadd any custom class you want
styleobjectany style which you want to override
heightnumberoptional, give only if you want to have a fixed height scrolling content
scrollableTargetnode or stringoptional, reference to a (parent) DOM element that is already providing overflow scrollbars to the InfiniteScroll component. You should provide the id of the DOM node preferably.
hasChildrenboolchildren is by default assumed to be of type array and it's length is used to determine if loader needs to be shown or not, if your children is not an array, specify this prop to tell if your items are 0 or more.
pullDownToRefreshboolto enable Pull Down to Refresh feature
pullDownToRefreshContentnodeany JSX that you want to show the user, default={<h3>Pull down to refresh</h3>}
releaseToRefreshContentnodeany JSX that you want to show the user, default={<h3>Release to refresh</h3>}
pullDownToRefreshThresholdnumberminimum distance the user needs to pull down to trigger the refresh, default=100px , a lower value may be needed to trigger the refresh depending your users browser.
refreshFunctionfunctionthis function will be called, it should return the fresh data that you want to show the user
initialScrollYnumberset a scroll y position for the component to render with.
inverseboolset infinite scroll on top

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Ankeet Maini

💬 📖 💻 👀 🚧

Darsh Shah

🚇

This project follows the all-contributors specification. Contributions of any kind are welcome!

LICENSE

MIT