react-infinite-scroll-component vs react-window-infinite-loader vs react-infinite-scroller
無限スクロールライブラリ
react-infinite-scroll-componentreact-window-infinite-loaderreact-infinite-scroller類似パッケージ:
無限スクロールライブラリ

無限スクロールライブラリは、ユーザーがスクロールすることでコンテンツを動的に読み込むためのツールです。これにより、ページネーションを使用せずに、シームレスなユーザー体験を提供します。これらのライブラリは、パフォーマンスを最適化し、ユーザーが必要なデータを迅速に取得できるように設計されています。

npmのダウンロードトレンド
3 年
GitHub Starsランキング
統計詳細
パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
react-infinite-scroll-component937,8643,048169 kB1984日前MIT
react-window-infinite-loader496,95295023 kB03ヶ月前MIT
react-infinite-scroller454,4613,30730.3 kB98-MIT
機能比較: react-infinite-scroll-component vs react-window-infinite-loader vs react-infinite-scroller

パフォーマンス最適化

  • react-infinite-scroll-component:

    このライブラリは、シンプルな無限スクロールを実現するために設計されており、基本的なパフォーマンス最適化が施されていますが、特に大量のデータを扱う場合には限界があります。

  • react-window-infinite-loader:

    仮想化技術を使用して、表示されているアイテムのみをレンダリングするため、パフォーマンスが非常に高く、大量のデータを扱う際に特に効果的です。

  • react-infinite-scroller:

    このライブラリは、スクロールイベントを効率的に管理し、必要なデータを動的に取得するための機能を提供します。パフォーマンスを向上させるためのカスタマイズオプションも豊富です。

使いやすさ

  • react-infinite-scroll-component:

    APIがシンプルで、ドキュメントも充実しているため、初心者でも簡単に導入できます。基本的な無限スクロール機能をすぐに実装できます。

  • react-window-infinite-loader:

    仮想化を利用するため、初めて使用する場合は少し学習コストがかかりますが、パフォーマンスが最優先されるプロジェクトにおいては非常に有用です。

  • react-infinite-scroller:

    やや複雑なAPIを持ちますが、柔軟性が高く、さまざまなカスタマイズが可能です。特に、特定の要件に合わせた実装が必要な場合に適しています。

カスタマイズ性

  • react-infinite-scroll-component:

    基本的な無限スクロール機能を提供しますが、カスタマイズの余地は限られています。シンプルな要件には適していますが、複雑な要件には不向きです。

  • react-window-infinite-loader:

    仮想化と無限スクロールの組み合わせにより、非常に高いカスタマイズ性を持っています。特に、データの表示方法や取得方法を柔軟に変更することが可能です。

  • react-infinite-scroller:

    多くのカスタマイズオプションを提供しており、特定のニーズに応じて機能を調整できます。特に、データの取得方法や表示方法を変更したい場合に便利です。

コミュニティとサポート

  • react-infinite-scroll-component:

    比較的新しいライブラリですが、活発なコミュニティがあり、サポートが充実しています。問題が発生した場合でも、解決策を見つけやすいです。

  • react-window-infinite-loader:

    このライブラリは、特にパフォーマンスに特化したコミュニティがあり、最適化に関する情報が豊富です。

  • react-infinite-scroller:

    広く使用されているため、豊富なリソースやサポートが存在します。多くの開発者が利用しているため、情報を見つけやすいです。

学習曲線

  • react-infinite-scroll-component:

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

  • react-window-infinite-loader:

    仮想化の概念を理解する必要があるため、他のライブラリに比べて学習曲線は急ですが、パフォーマンスを重視するプロジェクトには非常に有用です。

  • react-infinite-scroller:

    APIがやや複雑なため、初めて使用する際には少し学習が必要ですが、柔軟性のある機能を活用することで、より効果的な実装が可能です。

選び方: react-infinite-scroll-component vs react-window-infinite-loader vs react-infinite-scroller
  • react-infinite-scroll-component:

    シンプルで使いやすいAPIを求めている場合や、基本的な無限スクロール機能を必要とするプロジェクトに適しています。特に、Reactのコンポーネントスタイルに慣れている開発者にとっては、直感的に使用できます。

  • react-window-infinite-loader:

    パフォーマンスを重視し、特に大量のデータを処理する必要がある場合に最適です。仮想化を利用して、表示されているコンテンツのみをレンダリングすることで、メモリ使用量を削減し、スムーズなユーザー体験を提供します。

  • react-infinite-scroller:

    より高度な機能やカスタマイズ性を求める場合に適しています。特に、スクロール位置を管理したり、複雑なデータ構造を扱う必要がある場合に有効です。

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