react-virtualized vs react-window-infinite-loader vs react-virtual vs react-list vs react-infinite vs react-window
React 無限スクロールと仮想化ライブラリの技術選定ガイド
react-virtualizedreact-window-infinite-loaderreact-virtualreact-listreact-infinitereact-window類似パッケージ:

React 無限スクロールと仮想化ライブラリの技術選定ガイド

このドキュメントは、React アプリケーションで大規模なリストや無限スクロールを実装する際の主要なライブラリを比較しています。react-virtualized、react-window、react-virtual などの仮想化ライブラリから、react-infinite、react-list などの従来の無限スクロールコンポーネントまで、それぞれのアーキテクチャ、API デザイン、メンテナンス状況を分析します。パフォーマンス、柔軟性、開発者体験の観点から、プロジェクトに適した技術選定を行うための指針を提供します。

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

3 年

GitHub Starsランキング

統計詳細

パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
react-virtualized1,871,20227,0812.24 MB12年前MIT
react-window-infinite-loader758,71495123 kB07ヶ月前MIT
react-virtual654,5147,085158 kB112-MIT
react-list537,4111,97135.3 kB732ヶ月前MIT
react-infinite12,6882,683243 kB102-BSD-3-Clause
react-window017,206216 kB11ヶ月前MIT

React 無限スクロールと仮想化ライブラリ:アーキテクチャと実装の深層比較

大規模なリストを扱う際、すべてのアイテムを一度にレンダリングすると、ブラウザが重くなりユーザー体験が損なわれます。これを解決するため、表示されている部分だけを描画する「ウィンドウイング(仮想化)」技術や、スクロールに応じてデータを読み込む「無限スクロール」実装が必要になります。

今回は、react-infinite、react-list、react-virtual、react-virtualized、react-window、react-window-infinite-loader の 6 つのパッケージを比較し、それぞれの技術的特徴と適切な使いどころを明確にします。

🏗️ アーキテクチャ:コンポーネント型 vs ヘッドレス型

ライブラリを選ぶ際、まず「完成されたコンポーネントを提供するか」それとも「ロジックだけを提供するか(ヘッドレス)」という違いを理解する必要があります。

react-virtualized と react-window は、高度に最適化されたコンポーネントを提供します。

  • 内部で DOM 計算を最適化しており、設定項目を渡すだけで高速なリストが得られます。
  • 黒箱化された部分が多く、カスタマイズには一定の学習コストがかかります。
// react-window: 完成されたコンポーネントを使用
import { FixedSizeList } from 'react-window';

const Row = ({ index, style }) => (
  <div style={style}>Row {index}</div>
);

const List = () => (
  <FixedSizeList height={600} itemCount={1000} itemSize={35}>
    {Row}
  </FixedSizeList>
);

react-virtual はヘッドレスアプローチを採用しています。

  • UI に関する制限がなく、開発者が HTML 構造やスタイルを完全に制御できます。
  • 計算ロジック(どのアイテムを表示すべきか)だけをフックとして提供します。
// react-virtual: 仮想化ロジックだけをフックで取得
import { useVirtual } from 'react-virtual';
import { useRef } from 'react';

const List = () => {
  const parentRef = useRef();
  const virtual = useVirtual({
    size: 1000,
    parentRef,
    estimateSize: () => 35,
  });

  return (
    <div ref={parentRef} style={{ height: '600px', overflow: 'auto' }}>
      <div style={{ height: `${virtual.totalSize}px` }}>
        {virtual.virtualItems.map(item => (
          <div key={item.key} style={{ position: 'absolute', top: 0, transform: `translateY(${item.start}px)` }}>
            Row {item.index}
          </div>
        ))}
      </div>
    </div>
  );
};

react-infinite と react-list は、より単純なコンポーネント型ですが、内部最適化は古いです。

  • 仮想化というより、単純な無限スクロールイベントの検知に近いです。
  • 大量のデータがある場合、パフォーマンス劣化のリスクがあります。
// react-infinite: 単純なコンポーネント構成
import Infinite from 'react-infinite';

const List = () => (
  <Infinite elementHeight={50} containerHeight={600}>
    <div>Item 1</div>
    <div>Item 2</div>
    {/* 子要素をすべて渡す必要がある場合が多い */}
  </Infinite>
);

📦 保守性とメンテナンス状況

ライブラリの長期的なメンテナンスは、プロジェクトの安定性に直結します。

react-virtualized は事実上メンテナンスモードに入っています。

  • 作者である Brian Vaughn 氏自身によって、より軽量な react-window への移行が推奨されています。
  • 機能は豊富ですが、バンドルサイズが大きく、ツリーシェイキングが効きにくい構造です。

react-window が現在のデファクトスタンダードです。

  • react-virtualized の欠点を解消するために作られました。
  • API がモダンで、バンドルサイズも小さく、React の最新機能にも対応しています。

react-infinite と react-list は更新頻度が低いです。

  • 長期間更新がない場合が多く、現代の React バージョン(特に Strict Mode や Concurrent Features)との互換性に懸念があります。
  • 新規プロジェクトで採用すると、将来的な技術的負債になる可能性が高いです。

react-virtual は活発にメンテナンスされています。

  • TanStack (旧 React Table) のエコシステムの一部として開発されています。
  • React 以外のフレームワーク対応も視野に入れているため、設計が堅牢です。

🔄 無限ローディングの実装パターン

リストが無限に続く場合(ページネーションなしでスクロールするとデータが追加される)、追加のロジックが必要になります。

react-window-infinite-loader は、react-window のために作られた専用ラッパーです。

  • 「どのアイテムが既に読み込まれているか」を管理するロジックを提供します。
  • react-window と組み合わせることで、高性能な無限スクロールが実現できます。
// react-window-infinite-loader: 無限ローディングの管理
import InfiniteLoader from 'react-window-infinite-loader';
import { FixedSizeList } from 'react-window';

const isItemLoaded = (index) => !!items[index];
const loadMoreItems = (startIndex, stopIndex) => {
  // API を叩いてデータを取得し、items 配列を更新する
};

const List = () => (
  <InfiniteLoader
    isItemLoaded={isItemLoaded}
    itemCount={items.length}
    loadMoreItems={loadMoreItems}
  >
    {({ onItemsRendered, ref }) => (
      <FixedSizeList
        itemCount={items.length}
        itemSize={35}
        onItemsRendered={onItemsRendered}
        ref={ref}
      >
        {Row}
      </FixedSizeList>
    )}
  </InfiniteLoader>
);

react-virtual にも同様の機能がありますが、より低レベルです。

  • 開発者がスクロールイベントを監視し、自前でデータ取得ロジックを書く必要があります。
  • 自由度が高い分、実装コストは上がります。
// react-virtual: 自前でローディングロジックを制御
const virtual = useVirtual({
  size: items.length,
  parentRef,
  estimateSize: () => 35,
  overscan: 5,
});

// onScroll などで末端に達したことを検知し、loadMoreItems を発火させる必要がある

react-infinite は無限スクロールが主目的です。

  • 初期設計から無限スクロールを前提としているため、設定は簡単です。
  • しかし、内部で多くの DOM 要素を保持しようとする傾向があり、メモリ使用量が増大するリスクがあります。
// react-infinite: 無限スクロールイベントをトリガーに使用
<Infinite
  useWindowAsScrollContainer
  onInfiniteLoad={loadMoreItems}
  loadingSpinnerContainer={<div>Loading...</div>}
>
  {items.map(item => <div key={item.id}>{item.name}</div>)}
</Infinite>

⚡ パフォーマンスと最適化の仕組み

大量のデータを扱う場合、いかに DOM 操作を減らすかが鍵になります。

特徴react-window / react-virtualizedreact-virtualreact-infinite / react-list
レンダリング表示領域のみレンダリング(ウィンドウイング)表示領域のみレンダリング全要素を保持しようとする傾向
DOM 更新最小限に抑えられた更新開発者の実装に依存頻繁な更新が発生しやすい
スクロール専用コンテナでのスクロール制御任意のコンテナで制御可能ウィンドウスクロールに依存しがち
メモリ効率的効率的高負荷になりやすい

react-window は、アイテムのサイズが固定か変動かに応じてコンポーネントを使い分けます。

  • FixedSizeList: 高速。すべてのアイテムが同じ高さの場合。
  • VariableSizeList: 柔軟。アイテムの高さが異なる場合(計算コストが少し増える)。
// 固定サイズの場合(最速)
<FixedSizeList itemSize={50} ... />

// 可変サイズの場合(柔軟)
<VariableSizeList itemSize={index => getHeight(index)} ... />

react-virtualized も同様の機能を持ちますが、API が複雑です。

  • List、Grid、Table など用途別にコンポーネントが細分化されています。
  • 機能は強力ですが、不要な機能までバンドルに含まれやすい構造です。

🛠️ 開発者体験(DX)とカスタマイズ性

実装のしやすさや、デザインのカスタマイズ自由度も重要な選定基準です。

react-window はバランスが良いです。

  • 標準的なリストなら数行で実装できます。
  • カスタマイズには「レンダラープロップス」を介して行います。

react-virtual はカスタマイズ性が最高です。

  • 返ってくるのは数値(位置情報)と参照(ref)だけなので、HTML 構造は自由です。
  • 複雑なグリッドレイアウトや、特殊なアニメーションを組み込みたい場合に真価を発揮します。
// react-virtual: 自由な HTML 構造が可能
<div ref={parentRef}>
  {virtualItems.map(item => (
    <div key={item.key} style={{ ...item.measurements }}>
      {/* 中に何をいれても自由 */}
    </div>
  ))}
</div>

react-infinite は簡単ですが制限があります。

  • コンテナ構造が固定されており、CSS で自由に制御するのが難しい場合があります。
  • 現代の CSS 手法(Flexbox, Grid)との相性が悪いことがあります。

📊 選定マトリクス:どのライブラリを使うべきか

プロジェクトの要件に応じて、以下のように選定するのが合理的です。

要件推奨ライブラリ理由
標準的なリストreact-window軽量、高速、メンテナンスが活発
無限スクロールreact-window + react-window-infinite-loader組み合わせることで最強の性能と機能
完全なカスタマイズreact-virtualUI 制約がなく、ロジックのみ借用できる
レガシー維持react-virtualized既存実装がある場合のみ。新規は非推奨
シンプルな実装react-infinite非推奨。データ量少ならありだがリスク大
他フレームワークreact-virtual核心ロジックがフレームワーク非依存

💡 結論:現代のベストプラクティス

2024 年以降の React プロジェクトにおいて、リストの仮想化が必要な場合、react-window が最も堅実な選択です。特に react-window-infinite-loader と組み合わせることで、無限スクロールの課題も解決できます。API が直感的で、コミュニティのサポートも厚いため、トラブルが起きた際の解決も容易です。

一方、デザインシステムを自作していたり、リスト以外の複雑な仮想化(例えば、巨大なカレンダーやグリッド)が必要な場合は、react-virtual が優れた選択肢となります。ヘッドレスであるため、コンポーネントの設計に縛られず、パフォーマンスとデザインを両立できます。

react-virtualized、react-infinite、react-list については、既存プロジェクトのメンテナンス以外で新規に採用する理由はほとんどありません。これらは過去の技術的アプローチを反映しており、現代の React のパフォーマンス要件やエコシステムに最適化されていません。

技術選定では「できること」だけでなく「維持できること」も重要です。アクティブにメンテナンスされ、現代の Web 標準に沿ったライブラリを選ぶことが、長期的なプロジェクトの成功につながります。

選び方: react-virtualized vs react-window-infinite-loader vs react-virtual vs react-list vs react-infinite vs react-window

  • react-virtualized:

    既存のレガシーコードベースで既に導入されており、移行コストが大きい場合を除き、新規プロジェクトでは避けるべきです。react-window によって置き換えられた経緯があり、バンドルサイズや API の複雑さで劣ります。

  • react-window-infinite-loader:

    react-window を使用していて、さらに無限ローディング(スクロールに応じたデータ取得)機能が必要な場合に選択します。単体ではなく react-window と組み合わせて使用する専用コンポーネントです。

  • react-virtual:

    フレームワークに依存しないロジック(ヘッドレス)を求めたり、Vue や Svelte などの他フレームワークとの共用を想定する場合に最適です。TanStack ecosystem との親和性が高く、カスタマイズ性を重視するプロジェクトに向いています。

  • react-list:

    シンプルな実装で十分な場合や、非常に古いコードベースの維持が必要な場合に限り考慮します。機能性やパフォーマンス面で現代的な仮想化ライブラリに劣るため、新規開発では他の選択肢を優先してください。

  • react-infinite:

    レガシープロジェクトのメンテナンスを行う場合を除き、新規プロジェクトでの使用は推奨しません。メンテナンスが停滞しており、現代的な React のパターン(Hooks など)に準拠していないため、代替ライブラリへの移行を検討すべきです。

  • react-window:

    React 環境で標準的な仮想化リストを実装する際のファーストチョイスです。Brian Vaughn によって維持されており、API がシンプルで軽量、かつパフォーマンスが優れています。ほとんどのユースケースでバランスが最も取れています。

react-virtualized のREADME

React virtualized

React components for efficiently rendering large lists and tabular data. Check out the demo for some examples.

If you like this project, 🎉 become a sponsor or ☕ buy me a coffee

Sponsors

The following wonderful companies have sponsored react-virtualized:

Learn more about becoming a sponsor!

A word about react-window

If you're considering adding react-virtualized to a project, take a look at react-window as a possible lighter-weight alternative. Learn more about how the two libraries compare here.

Getting started

Install react-virtualized using npm.

npm install react-virtualized --save

ES6, CommonJS, and UMD builds are available with each distribution. For example:

// Most of react-virtualized's styles are functional (eg position, size).
// Functional styles are applied directly to DOM elements.
// The Table component ships with a few presentational styles as well.
// They are optional, but if you want them you will need to also import the CSS file.
// This only needs to be done once; probably during your application's bootstrapping process.
import 'react-virtualized/styles.css';

// You can import any component you want as a named export from 'react-virtualized', eg
import {Column, Table} from 'react-virtualized';

// But if you only use a few react-virtualized components,
// And you're concerned about increasing your application's bundle size,
// You can directly import only the components you need, like so:
import AutoSizer from 'react-virtualized/dist/commonjs/AutoSizer';
import List from 'react-virtualized/dist/commonjs/List';

Note webpack 4 makes this optimization itself, see the documentation.

If the above syntax looks too cumbersome, or you import react-virtualized components from a lot of places, you can also configure a Webpack alias. For example:

// Partial webpack.config.js
{
  alias: {
    'react-virtualized/List': 'react-virtualized/dist/es/List',
  },
  ...rest
}

Then you can just import like so:

import List from 'react-virtualized/List';

// Now you can use <List {...props} />

You can also use a global-friendly UMD build:

<link rel="stylesheet" href="path-to-react-virtualized/styles.css" />
<script src="path-to-react-virtualized/dist/umd/react-virtualized.js"></script>

Now you're ready to start using the components. You can learn more about which components react-virtualized has to offer below.

Dependencies

React Virtualized has very few dependencies and most are managed by NPM automatically. However the following peer dependencies must be specified by your project in order to avoid version conflicts: react, react-dom. NPM will not automatically install these for you but it will show you a warning message with instructions on how to install them.

Pure Components

By default all react-virtualized components use shallowCompare to avoid re-rendering unless props or state has changed. This occasionally confuses users when a collection's data changes (eg ['a','b','c'] => ['d','e','f']) but props do not (eg array.length).

The solution to this is to let react-virtualized know that something external has changed. This can be done a couple of different ways.

Pass-thru props

The shallowCompare method will detect changes to any props, even if they aren't declared as propTypes. This means you can also pass through additional properties that affect cell rendering to ensure changes are detected. For example, if you're using List to render a list of items that may be re-sorted after initial render- react-virtualized would not normally detect the sort operation because none of the properties it deals with change. However you can pass through the additional sort property to trigger a re-render. For example:

<List {...listProps} sortBy={sortBy} />
Public methods

Grid and Collection components can be forcefully re-rendered using forceUpdate. For Table and List, you'll need to call forceUpdateGrid to ensure that the inner Grid is also updated. For MultiGrid, you'll need to call forceUpdateGrids to ensure that the inner Grids are updated.

Documentation

API documentation available here.

There are also a couple of how-to guides:

Examples

Examples for each component can be seen in the documentation.

Here are some online demos of each component:

And here are some "recipe" type demos:

Supported Browsers

react-virtualized aims to support all evergreen browsers and recent mobile browsers for iOS and Android. IE 9+ is also supported (although IE 9 will require some user-defined, custom CSS since flexbox layout is not supported).

If you find a browser-specific problem, please report it along with a repro case. The easiest way to do this is probably by forking this Plunker.

Friends

Here are some great components built on top of react-virtualized:

  • react-infinite-calendar: Infinite scrolling date-picker with localization, themes, keyboard support, and more
  • react-sortable-hoc: Higher-order components to turn any list into an animated, touch-friendly, sortable list
  • react-sortable-tree: Drag-and-drop sortable representation of hierarchical data
  • react-virtualized-checkbox: Checkbox group component with virtualization for large number of options
  • react-virtualized-select: Drop-down menu for React with windowing to support large numbers of options.
  • react-virtualized-tree: A reactive tree component that aims to render large sets of tree structured data in an elegant and performant way
  • react-timeline-9000: A calendar timeline component that is capable of displaying and interacting with a large number of items

Contributions

Use GitHub issues for requests.

I actively welcome pull requests; learn how to contribute.

Changelog

Changes are tracked in the changelog.

License

react-virtualized is available under the MIT License.