react-infinite、react-list、react-tiny-virtual-list、react-virtualized、react-window は、すべて React アプリケーションで大量のデータを効率的にレンダリングするためのライブラリです。これらは「仮想スクロール(Virtual Scrolling)」または「ウィンドウ化(Windowing)」と呼ばれる技術を用いて、画面に見える部分のアイテムのみを DOM に描画し、パフォーマンスを最適化します。react-virtualized は長く愛されてきた包括的なソリューションですが、現在は react-window への移行が推奨されています。react-window はより軽量でモダンな API を提供します。一方、react-infinite や react-list はよりシンプルな実装を目指していますが、機能性やメンテナンス状況に違いがあります。
大量のデータを扱う React アプリケーションでは、すべてのアイテムを一度に DOM に描画するとブラウザが重くなり、スクロールが卡顿します。これを解決するのが「仮想スクロール」です。react-infinite、react-list、react-tiny-virtual-list、react-virtualized、react-window は、この課題に対する異なるアプローチを取っています。ここでは、実装方法、API の設計、そしてメンテナンス状況を比較します。
各ライブラリは、リストを表示するためのコンポーネントを提供していますが、その API 設計には大きな違いがあります。
react-window は、FixedSizeList や VariableSizeList といった明確なコンポーネントを提供します。アイテムの高さが固定か可変かで使い分けます。
// react-window
import { FixedSizeList } from 'react-window';
const Row = ({ index, style }) => (
<div style={style}>Item {index}</div>
);
const List = () => (
<FixedSizeList
height={400}
itemCount={1000}
itemSize={35}
width="100%"
>
{Row}
</FixedSizeList>
);
react-virtualized は、List コンポーネントを使用しますが、プロパティ名が異なり、少し冗長です。
// react-virtualized
import { List } from 'react-virtualized';
const Row = ({ index, key, style }) => (
<div key={key} style={style}>Item {index}</div>
);
const List = () => (
<List
width={600}
height={400}
rowCount={1000}
rowHeight={35}
rowRenderer={Row}
/>
);
react-infinite は、コンテナにアイテムを直接渡す方式が多く、仮想化というよりは「無限ロード」に焦点を当てています。
// react-infinite
import Infinite from 'react-infinite';
const List = () => (
<Infinite
elementHeight={35}
containerHeight={400}
>
{items.map(item => <div key={item.id}>{item.name}</div>)}
</Infinite>
);
react-list は、itemRenderer を使ってアイテムを描画します。設定はシンプルですが、カスタマイズ性は低めです。
// react-list
import List from 'react-list';
const Item = (key, index) => <div key={key}>Item {index}</div>;
const ListComponent = ({ items }) => (
<List
itemRenderer={Item}
length={items.length}
type="uniform"
estimatedItemSize={35}
/>
);
react-tiny-virtual-list は、その名の通り最小限のプロパティで動作します。
// react-tiny-virtual-list
import VirtualList from 'react-tiny-virtual-list';
const List = ({ items }) => (
<VirtualList
width={600}
height={400}
itemCount={items.length}
itemSize={35}
renderItem={({ index, style }) => (
<div key={index} style={style}>Item {index}</div>
)}
/>
);
データがページネーションされている場合、スクロールに合わせて追加でデータを読み込む必要があります。この実装方法もライブラリによって異なります。
react-window は、InfiniteLoader コンポーネントを別途提供しており、リストと組み合わせることで実装します。これが最もモダンなアプローチです。
// react-window
import { FixedSizeList } from 'react-window';
import { InfiniteLoader } from 'react-window-infinite-loader';
const InfiniteList = ({ items, loadMoreItems }) => (
<InfiniteLoader
itemCount={items.length}
loadMoreItems={loadMoreItems}
isItemLoaded={index => !!items[index]}
>
{({ onItemsRendered, ref }) => (
<FixedSizeList
ref={ref}
onItemsRendered={onItemsRendered}
itemCount={items.length}
itemSize={35}
height={400}
width="100%"
>
{Row}
</FixedSizeList>
)}
</InfiniteLoader>
);
react-virtualized も同様に InfiniteLoader を提供しますが、react-window のものと API が異なります。
// react-virtualized
import { List, InfiniteLoader } from 'react-virtualized';
const InfiniteList = ({ items, loadMoreItems }) => (
<InfiniteLoader
rowCount={items.length}
loadMoreRows={loadMoreItems}
isRowLoaded={({ index }) => !!items[index]}
>
{({ onRowsRendered, registerChild }) => (
<List
ref={registerChild}
onRowsRendered={onRowsRendered}
rowCount={items.length}
rowHeight={35}
height={400}
width={600}
rowRenderer={Row}
/>
)}
</InfiniteLoader>
);
react-infinite は、パッケージ名が示す通り、無限ロードが主要機能です。onInfiniteLoad プロパティを使用します。
// react-infinite
import Infinite from 'react-infinite';
const List = ({ items, handleInfiniteLoad }) => (
<Infinite
elementHeight={35}
containerHeight={400}
onInfiniteLoad={handleInfiniteLoad}
infiniteLoadBeginBottomOffset={200}
>
{items.map(item => <div key={item.id}>{item.name}</div>)}
</Infinite>
);
react-list には、無限ロードのための専用コンポーネントはありません。スクロールイベントを監視して自分で実装する必要があります。
// react-list
import List from 'react-list';
// 自分で scroll イベントを監視して loadMore を呼ぶ
const ListWithLoad = ({ items, loadMore }) => (
<div onScroll={checkScrollAndLoadMore}>
<List
itemRenderer={Item}
length={items.length}
type="uniform"
/>
</div>
);
react-tiny-virtual-list にも無限ロードの専用機能はありません。react-window と同様に、外部でスクロール位置を検知してデータを読み込むロジックを追加する必要があります。
// react-tiny-virtual-list
import VirtualList from 'react-tiny-virtual-list';
// onScroll イベントを利用して実装
const List = ({ items, loadMore }) => (
<VirtualList
width={600}
height={400}
itemCount={items.length}
itemSize={35}
onScroll={e => handleScroll(e, loadMore)}
renderItem={({ index, style }) => (
<div key={index} style={style}>Item {index}</div>
)}
/>
);
ライブラリを選ぶ際、メンテナンス状況はパフォーマンス以上に重要です。バグ修正や React の新バージョンへの対応が行われているか確認する必要があります。
react-virtualized は、かつての標準でしたが、現在は メンテナンスモード に入っています。作者自身によって react-window への移行が強く推奨されています。新規プロジェクトでの使用は避けるべきです。
// react-virtualized (非推奨)
// 新規プロジェクトでは使用しないでください
import { List } from 'react-virtualized';
react-window は、react-virtualized の作者によって作成され、現在も 活発にメンテナンス されています。React の新機能への対応も早く、最も信頼性が高い選択肢です。
// react-window (推奨)
import { FixedSizeList } from 'react-window';
react-infinite、react-list、react-tiny-virtual-list は、更新頻度が低く、長期間更新されていない可能性があります。これらは「動作すれば OK」という小規模なプロジェクトでは使えますが、エンタープライズレベルのアプリケーションではリスクになります。
// react-infinite, react-list, react-tiny-virtual-list
// メンテナンスが停止している可能性が高く、注意が必要
import Infinite from 'react-infinite';
リストのアイテムを単なるテキストではなく、複雑なコンポーネントにしたい場合、各ライブラリの拡張性が問われます。
react-window は、outerRef や innerRef を使ってスクロールバーや内部コンテナに直接アクセスできます。また、ItemData プロパティを使って、レンダリング関数に追加のデータを渡すことができます。
// react-window
<List
itemData={{ theme: 'dark' }}
// ...other props
>
{({ index, style, data }) => (
<div style={style} className={data.theme}>
{index}
</div>
)}
</List>
react-virtualized も同様の機能を持ちますが、プロパティ名が rowData など異なっており、混乱しやすいです。
// react-virtualized
<List
rowData={{ theme: 'dark' }}
// ...other props
rowRenderer={({ index, style, rowData }) => (
<div style={style} className={rowData.theme}>
{index}
</div>
)}
/>
react-infinite は、コンテナ内の要素をそのままレンダリングするため、カスタマイズは容易ですが、仮想化の恩恵(メモリ使用量の削減)が受けられない場合があります。
// react-infinite
<Infinite>
<CustomComponent theme="dark" />
</Infinite>
react-list と react-tiny-virtual-list は、カスタマイズのためのフックやプロパティが限られています。複雑なインタラクションが必要な場合、実装が難しくなることがあります。
// react-list
<List
itemRenderer={(key, index) => <CustomComponent key={key} />}
// 追加データを渡す標準的な方法が限られている
/>
| 特徴 | react-window | react-virtualized | react-infinite | react-list | react-tiny-virtual-list |
|---|---|---|---|---|---|
| メンテナンス | ✅ 活発 | ⚠️ メンテナンスモード | ❓ 不明/低 | ❓ 不明/低 | ❓ 不明/低 |
| バンドルサイズ | 小 | 大 | 中 | 小 | 極小 |
| API のシンプルさ | ✅ 高い | ❌ 低い | ✅ 高い | ✅ 高い | ✅ 高い |
| 無限ロード | ✅ 専用コンポーネント | ✅ 専用コンポーネント | ✅ 内蔵 | ❌ 手動 | ❌ 手動 |
| 推奨度 | 🏆 最高 | 🚫 非推奨 | ⚠️ 注意 | ⚠️ 注意 | ⚠️ 注意 |
react-window が現在のベストチョイスです。軽量で、API が整理されており、何よりメンテナンスが確実です。react-virtualized から移行するコストも低く設計されています。
react-virtualized は、既存のプロジェクトで既に使われている場合を除き、新規採用すべきではありません。機能は豊富ですが、その重さと保守性の低さがデメリットです。
react-infinite、react-list、react-tiny-virtual-list は、特定のシンプルなユースケースでは有用ですが、長期的な視点では react-window を使う方が安全です。特に、無限ロード機能をネイティブでサポートしている react-window の InfiniteLoader は、実装のミスを減らすのに役立ちます。
最終的には、「メンテナンスが活発か」 と 「API が明確か」 の 2 点が重要です。その点で react-window は他を圧倒しています。
新規プロジェクトでは react-window を首选してください。同じ作者によって react-virtualized の課題を解決するために作られており、バンドルサイズが小さく、API もシンプルです。メンテナンスが活発で、現在の React エコシステムにおける事実上の標準です。
既存のレガシープロジェクトで既に導入されている場合はそのまま使い続けても問題ありません。しかし、新規プロジェクトでの採用は避けるべきです。機能は豊富ですが、サイズが大きく、API が複雑で、現在はメンテナンスモードに入っています。
非常にシンプルな実装で、依存関係を最小限に抑えたい場合に適しています。しかし、機能が少ないため、複雑なレイアウトや高度な最適化が必要なプロジェクトには不向きです。
バンドルサイズを極限まで小さくしたい場合の選択肢ですが、メンテナンスが停止している可能性が高く、機能も限定的です。長期のプロジェクトでは react-window の方が安全です。
単純な「無限スクロール」実装のみが必要で、仮想化(DOM ノードの再利用)が必須でない場合に検討します。ただし、メンテナンス状況が不明確なことが多く、大規模なリストではパフォーマンス劣化のリスクがあるため、react-window の InfiniteLoader との併用を推奨します。
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.
If you like this project there are several ways to support it:
The following wonderful companies and individuals have sponsored react-window:
Begin by installing the library from NPM:
npm install react-window
TypeScript definitions are included within the published dist folder
Frequently asked questions can be found here.
Documentation for this project is available at react-window.vercel.app.
Renders data with many rows.
| Name | Description |
|---|---|
| rowComponent | React component responsible for rendering a row. This component will receive an ℹ️ Spread ℹ️ The prop types for this component are exported as |
| rowCount | Number of items to be rendered in the list. |
| rowHeight | Row height; the following formats are supported:
ℹ️ Percentage heights can't be resolved during server rendering unless a ⚠️ 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 |
| Name | Description |
|---|---|
| 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 rows). This property can be used to render things like overlays or tooltips. |
| defaultHeight | Default height of list (in pixels) for initial render, before its actual height has been measured. ℹ️ Lists can't be measured during server rendering, so this value determines how many rows are server rendered.
It's recommended to set this to the expected height of the list (or to specify a pixel height via the |
| defaultScrollOffset | Initial scroll offset (in pixels) of the list. This value is only applied once, when the list first mounts with at least one row. ℹ️ Server-rendered HTML can't be pre-scrolled, so server rendering always starts at the first row; the default scroll offset is applied once the list hydrates. ⚠️ If the list can't be scrolled that far when the offset is applied (e.g. it is hidden with |
| 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 |
| 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. |
| rowKey | Lists use the row index as a ℹ️ Custom keys can ensure better UX for sortable or filterable lists, particularly if your row components are stateful. Refer to the React documentation for more info. ⚠️ This prop cannot be auto-memoized because it is called during render.
It is important to always |
| scrollElement | Element that scrolls the list, for lists that scroll along with other content (e.g. the page):
The list renders at its full height and only renders the rows visible within the scroll element's viewport. Its position within the scroll element is measured whenever it renders, scrolls, or resizes, and whenever content before it is resized, inserted, or removed (e.g. an image loading above the list).
ℹ️ While the scroll element is ⚠️ The list itself doesn't scroll, so its |
| 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. |
Renders data with many rows and columns.
ℹ️ Unlike List rows, Grid cell sizes must be known ahead of time.
Either static sizes or something that can be derived (from the data in CellProps) without rendering.
| Name | Description |
|---|---|
| cellComponent | React component responsible for rendering a cell. This component will receive ℹ️ The prop types for this component are exported as |
| 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 |
| columnCount | Number of columns to be rendered in the grid. |
| columnWidth | Column width; the following formats are supported:
ℹ️ Percentage widths can't be resolved during server rendering unless a |
| rowCount | Number of rows to be rendered in the grid. |
| rowHeight | Row height; the following formats are supported:
ℹ️ Percentage heights can't be resolved during server rendering unless a |
| Name | Description |
|---|---|
| className | CSS class name. |
| dir | Indicates the directionality of grid cells. ℹ️ The directionality of an ancestor element can't be detected during server rendering; specify this prop explicitly for server-rendered right-to-left grids. ℹ️ See HTML |
| 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. |
| columnKey | Grids use the column index as a ℹ️ Custom keys can ensure better UX for sortable or filterable grids, particularly if your cell components are stateful. Refer to the React documentation for more info. ⚠️ This prop cannot be auto-memoized because it is called during render.
It is important to always |
| defaultHeight | Default height of grid (in pixels) for initial render, before its actual height has been measured. ℹ️ Grids can't be measured during server rendering, so this value determines how many rows are server rendered.
It's recommended to set this to the expected height of the grid (or to specify a pixel height via the |
| defaultScrollLeft | Initial horizontal scroll offset (in pixels) of the grid. This value is only applied once, when the grid first mounts with at least one column. ℹ️ Server-rendered HTML can't be pre-scrolled, so server rendering always starts at the first column; the default scroll offset is applied once the grid hydrates. ⚠️ If the grid can't be scrolled that far when the offset is applied (e.g. it is hidden with |
| defaultScrollTop | Initial vertical scroll offset (in pixels) of the grid. This value is only applied once, when the grid first mounts with at least one row. ℹ️ Server-rendered HTML can't be pre-scrolled, so server rendering always starts at the first row; the default scroll offset is applied once the grid hydrates. ⚠️ If the grid can't be scrolled that far when the offset is applied (e.g. it is hidden with |
| defaultWidth | Default width of grid (in pixels) for initial render, before its actual width has been measured. ℹ️ Grids can't be measured during server rendering, so this value determines how many columns are server rendered.
It's recommended to set this to the expected width of the grid (or to specify a pixel width via the |
| gridRef | Imperative Grid API. ℹ️ The |
| 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. |
| rowKey | Grids use the row index as a ℹ️ Custom keys can ensure better UX for sortable or filterable grids, particularly if your cell components are stateful. Refer to the React documentation for more info. ⚠️ This prop cannot be auto-memoized because it is called during render.
It is important to always |
| scrollElement | Element that scrolls the grid, for grids that scroll along with other content (e.g. the page):
The grid renders at its full height and only renders the rows (and columns) visible within the scroll element's viewport. Its position within the scroll element is measured whenever it renders, scrolls, or resizes, and whenever content before it is resized, inserted, or removed (e.g. an image loading above the grid).
ℹ️ While the scroll element is ⚠️ The grid's |
| tagName | Can be used to override the root HTML element rendered by the Grid component. The default value is "div", meaning that Grid renders an HTMLDivElement as its root. ⚠️ In most use cases the default ARIA roles are sufficient and this prop is not needed. |