react-window vs react-virtualized vs react-infinite-scroller
無限スクロールと仮想化ライブラリ
react-windowreact-virtualizedreact-infinite-scroller類似パッケージ:
無限スクロールと仮想化ライブラリ

これらのライブラリは、Reactアプリケーションにおいて大量のデータを効率的に表示するためのツールです。無限スクロールは、ユーザーがスクロールすることで新しいデータを自動的に読み込む機能を提供し、仮想化は表示されている部分だけをレンダリングすることでパフォーマンスを向上させます。これにより、ユーザー体験が向上し、アプリケーションの応答性が改善されます。

npmのダウンロードトレンド
3 年
GitHub Starsランキング
統計詳細
パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
react-window3,613,11516,985206 kB11ヶ月前MIT
react-virtualized1,242,77827,0362.24 MB110ヶ月前MIT
react-infinite-scroller429,4053,30830.3 kB98-MIT
機能比較: react-window vs react-virtualized vs react-infinite-scroller

無限スクロールの実装

  • react-window:

    react-windowも無限スクロールをサポートしていますが、主に仮想化に特化しており、簡単に無限スクロールを実装するための機能が用意されています。

  • react-virtualized:

    react-virtualizedは無限スクロールの機能を持っており、リストが長くなると自動的に新しいデータを読み込むことができますが、主に仮想化に焦点を当てています。無限スクロールを実装するには、追加の設定が必要です。

  • react-infinite-scroller:

    react-infinite-scrollerは、スクロールイベントをリッスンし、ユーザーがリストの最後に近づくと自動的に新しいデータを読み込む機能を提供します。これにより、ユーザーはページを切り替えることなく、シームレスにコンテンツを閲覧できます。APIはシンプルで、簡単にカスタマイズ可能です。

パフォーマンス

  • react-window:

    react-windowは、軽量でシンプルな設計により、パフォーマンスが非常に高いです。必要な部分だけをレンダリングするため、メモリ使用量が少なく、特に小規模なプロジェクトやシンプルなリストに最適です。

  • react-virtualized:

    react-virtualizedは、仮想化を利用して表示されている部分だけをレンダリングするため、非常に高いパフォーマンスを発揮します。リストやグリッドのサイズに関係なく、スムーズなユーザー体験を提供します。

  • react-infinite-scroller:

    このライブラリは、無限スクロールを実現するために最適化されており、ユーザーがスクロールするたびに必要なデータだけを読み込むため、パフォーマンスが向上します。ただし、データの読み込み方法やAPIの使用方法によっては、パフォーマンスに影響を与える可能性があります。

APIのシンプルさ

  • react-window:

    react-windowは、シンプルなAPIを提供しており、仮想化を簡単に実装できます。特に、シンプルなリストやグリッドを扱う場合に適しています。

  • react-virtualized:

    react-virtualizedは多機能ですが、APIはやや複雑で、学習曲線が急です。多くの機能を持っているため、使いこなすには時間がかかるかもしれません。

  • react-infinite-scroller:

    react-infinite-scrollerは、シンプルで直感的なAPIを提供しており、無限スクロールを簡単に実装できます。特に初心者にとって使いやすいライブラリです。

カスタマイズ性

  • react-window:

    react-windowは、カスタマイズ性が高く、基本的な機能を提供しつつ、必要に応じて拡張することができます。シンプルなプロジェクトに最適です。

  • react-virtualized:

    react-virtualizedは、非常に多くのカスタマイズオプションを提供しており、特定の要件に応じた高度な設定が可能です。ただし、カスタマイズには深い理解が必要です。

  • react-infinite-scroller:

    react-infinite-scrollerは、カスタマイズが容易で、ユーザーのニーズに合わせて無限スクロールの動作を調整できます。特定の条件に基づいてデータを読み込むロジックを簡単に追加できます。

サポートとメンテナンス

  • react-window:

    react-windowは、比較的新しいライブラリですが、活発にメンテナンスされており、シンプルな設計のおかげでドキュメントも分かりやすいです。

  • react-virtualized:

    react-virtualizedは、広く使用されているライブラリであり、豊富なドキュメントとコミュニティサポートがあります。しかし、機能が多いため、特定の問題に対する解決策を見つけるのが難しい場合があります。

  • react-infinite-scroller:

    react-infinite-scrollerは、活発にメンテナンスされており、コミュニティからのサポートも充実しています。ドキュメントも整備されており、問題解決が容易です。

選び方: react-window vs react-virtualized vs react-infinite-scroller
  • react-window:

    軽量でシンプルな仮想化ソリューションが必要な場合はreact-windowを選択してください。react-virtualizedの軽量版として設計されており、基本的な機能を提供しつつ、より簡潔なAPIを持っています。

  • react-virtualized:

    非常に大きなリストやテーブルを扱う場合、特にパフォーマンスが重要な場合はreact-virtualizedを選択してください。このライブラリは、リストやグリッドの仮想化を提供し、必要な部分だけをレンダリングすることで、メモリ使用量と描画時間を大幅に削減します。

  • react-infinite-scroller:

    大量のデータをページングするのではなく、ユーザーがスクロールすることでデータを動的に読み込む必要がある場合は、react-infinite-scrollerを選択してください。特に、無限スクロールの実装が簡単で、シンプルなAPIを提供しています。

react-window のREADME

react-window

react-window is a component library that helps render large lists of data quickly and without the performance problems that often go along with rendering a lot of data. It's used in a lot of places, from React DevTools to the Replay browser.

Support

If you like this project there are several ways to support it:

The following wonderful companies and individuals have sponsored react-window:

Installation

Begin by installing the library from NPM:

npm install react-window

TypeScript types

TypeScript definitions are included within the published dist folder

Documentation

Documentation for this project is available at react-window.vercel.app; version 1.x documentation can be found at react-window-v1.vercel.app.

List

Required props

NameDescription
rowComponent

React component responsible for rendering a row.

This component will receive an index and style prop by default. Additionally it will receive prop values passed to rowProps.

ℹ️ The prop types for this component are exported as RowComponentProps

rowCount

Number of items to be rendered in the list.

rowHeight

Row height; the following formats are supported:

  • number of pixels (number)
  • percentage of the grid's current height (string)
  • function that returns the row height (in pixels) given an index and cellProps
  • dynamic row height cache returned by the useDynamicRowHeight hook

⚠️ Dynamic row heights are not as efficient as predetermined sizes. It's recommended to provide your own height values if they can be determined ahead of time.

rowProps

Additional props to be passed to the row-rendering component. List will automatically re-render rows when values in this object change.

⚠️ This object must not contain ariaAttributes, index, or style props.

Optional props

NameDescription
className

CSS class name.

style

Optional CSS properties. The list of rows will fill the height defined by this style.

children

Additional content to be rendered within the list (above cells). This property can be used to render things like overlays or tooltips.

defaultHeight

Default height of list for initial render. This value is important for server rendering.

listRef

Ref used to interact with this component's imperative API.

This API has imperative methods for scrolling and a getter for the outermost DOM element.

ℹ️ The useListRef and useListCallbackRef hooks are exported for convenience use in TypeScript projects.

onResize

Callback notified when the List's outermost HTMLElement resizes. This may be used to (re)scroll a row into view.

onRowsRendered

Callback notified when the range of visible rows changes.

overscanCount

How many additional rows to render outside of the visible area. This can reduce visual flickering near the edges of a list when scrolling.

tagName

Can be used to override the root HTML element rendered by the List component. The default value is "div", meaning that List renders an HTMLDivElement as its root.

⚠️ In most use cases the default ARIA roles are sufficient and this prop is not needed.

Grid

Required props

NameDescription
cellComponent

React component responsible for rendering a cell.

This component will receive an index and style prop by default. Additionally it will receive prop values passed to cellProps.

ℹ️ The prop types for this component are exported as CellComponentProps

cellProps

Additional props to be passed to the cell-rendering component. Grid will automatically re-render cells when values in this object change.

⚠️ This object must not contain ariaAttributes, columnIndex, rowIndex, or style props.

columnCount

Number of columns to be rendered in the grid.

columnWidth

Column width; the following formats are supported:

  • number of pixels (number)
  • percentage of the grid's current width (string)
  • function that returns the row width (in pixels) given an index and cellProps
rowCount

Number of rows to be rendered in the grid.

rowHeight

Row height; the following formats are supported:

  • number of pixels (number)
  • percentage of the grid's current height (string)
  • function that returns the row height (in pixels) given an index and cellProps

Optional props

NameDescription
className

CSS class name.

dir

Corresponds to the HTML dir attribute: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/dir

style

Optional CSS properties. The grid of cells will fill the height and width defined by this style.

children

Additional content to be rendered within the grid (above cells). This property can be used to render things like overlays or tooltips.

defaultHeight

Default height of grid for initial render. This value is important for server rendering.

defaultWidth

Default width of grid for initial render. This value is important for server rendering.

gridRef

Ref used to interact with this component's imperative API.

This API has imperative methods for scrolling and a getter for the outermost DOM element.

ℹ️ The useGridRef and useGridCallbackRef hooks are exported for convenience use in TypeScript projects.

onCellsRendered

Callback notified when the range of rendered cells changes.

onResize

Callback notified when the Grid's outermost HTMLElement resizes. This may be used to (re)scroll a cell into view.

overscanCount

How many additional rows/columns to render outside of the visible area. This can reduce visual flickering near the edges of a grid when scrolling.

tagName

Can be used to override the root HTML element rendered by the List component. The default value is "div", meaning that List renders an HTMLDivElement as its root.

⚠️ In most use cases the default ARIA roles are sufficient and this prop is not needed.