react-window vs react-virtualized vs react-virtual
大規模リストの仮想化とレンダリング戦略
react-windowreact-virtualizedreact-virtual유사 패키지:

大規模リストの仮想化とレンダリング戦略

react-virtualized、react-window、react-virtual は、React アプリケーションで数千行を超えるリストやテーブルをパフォーマンス低下なく表示するためのライブラリです。これらは「ウィンドウ化」(仮想化)技術を用いて、現在画面に見えているアイテムだけをレンダリングし、スクロールに応じて内容を入れ替える仕組みを持っています。react-virtualized はかつての標準でしたが、現在は react-window への移行が推奨されています。react-virtual はフックベースのヘッドレスアプローチを提供しますが、現在は @tanstack/react-virtual へ統合されています。

npm 다운로드 트렌드

3 년

GitHub Stars 순위

통계 세부사항

패키지
다운로드
Stars
크기
Issues
발행일
라이선스
react-window8,413,68617,200419 kB18時間前MIT
react-virtualized2,311,88927,0671.31 MB112日前MIT
react-virtual654,6957,178158 kB84-MIT

大規模リストの仮想化:react-virtualized vs react-window vs react-virtual

React で数千件以上のデータを表示する際、すべてを一度に描画するとブラウザが重くなり操作不能になります。これを防ぐため、見える部分だけを描画する「仮想化」技術が必要です。react-virtualized、react-window、react-virtual はこの課題を解決する代表的なライブラリですが、設計思想と使い方が大きく異なります。

🏗️ 設計思想:コンポーネント提供 vs ヘッドレス

react-virtualized は、リストやグリッドのための完成されたコンポーネントを提供します。

  • 用意された <List> や <Grid> を使います。
  • 内部構造が隠蔽されており、カスタマイズには制限があります。
// react-virtualized: 完成されたコンポーネントを使用
import { List } from 'react-virtualized';

<List
  width={600}
  height={400}
  rowCount={1000}
  rowRenderer={({ index, style }) => (
    <div style={style}>Row {index}</div>
  )}
/>

react-window もコンポーネントを提供しますが、より軽量でシンプルです。

  • react-virtualized の問題点を解消するために作られました。
  • API が整理されており、不要な機能が削ぎ落とされています。
// react-window: 軽量なコンポーネントを使用
import { FixedSizeList } from 'react-window';

<FixedSizeList
  width={600}
  height={400}
  itemCount={1000}
  itemSize={35}
>
  {({ index, style }) => (
    <div style={style}>Row {index}</div>
  )}
</FixedSizeList>

react-virtual は、UI を提供しない「ヘッドレス」なフックです。

  • 計測と計算だけを行い、描画は開発者が任されます。
  • 自由度高いですが、自分で DOM 構造を作る必要があります。
  • ※ 注意:このパッケージは非推奨で、現在は @tanstack/react-virtual が正式です。
// react-virtual: フックで計測だけ行う(非推奨パッケージ)
import { useVirtual } from 'react-virtual';

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

return (
  <div ref={parentRef}>
    <div style={{ height: virtual.getTotalSize() }}>
      {virtual.virtualItems.map(item => (
        <div key={item.key} style={{ transform: `translateY(${item.start}px)` }}>
          Row {item.index}
        </div>
      ))}
    </div>
  </div>
);

📦 導入と設定の手間

ライブラリの選び方は、プロジェクトの柔軟性要件によります。

  • react-virtualized は設定項目が多く、初期コストが高いです。古い設計のため、現代の React 機能(例:Hooks)との相性が良くありません。
  • react-window は必要十分な機能に絞られており、導入が簡単です。標準的なユースケースならこれで十分です。
  • react-virtual は DOM 構造を自分で組むため、自由なレイアウトが可能です。しかし、その分手間がかかります。

💡 ヒント:react-virtual パッケージは現在メンテナンスされていません。同等の機能が必要な場合は @tanstack/react-virtual を使用してください。

📏 可変サイズアイテムの扱い

アイテムの高さが一定でない場合(例:チャットログ、コメント欄)、各ライブラリの対応は以下の通りです。

react-virtualized は CellMeasurer と言うコンポーネントで計測します。

  • 一度レンダリングしてからサイズを測るため、初期表示に遅延が出ることがあります。
// react-virtualized: CellMeasurer で計測
<CellMeasurerCache defaultHeight={100}>
  <List
    rowRenderer={({ index, style, parent }) => (
      <CellMeasurer key={index} cache={cache} parent={parent} index={index}>
        {({ measure, height }) => (
          <div style={style} onLoad={measure}>
            Content {index}
          </div>
        )}
      </CellMeasurer>
    )}
  />
</CellMeasurerCache>

react-window は VariableSizeList コンポーネントを使います。

  • 開発者がサイズを管理し、変更時に resetAfterIndex で通知します。
// react-window: 可変サイズリスト
import { VariableSizeList } from 'react-window';

<VariableSizeList
  itemCount={1000}
  itemSize={index => heights[index]}
  onItemsRendered={({ visibleStopIndex }) => {
    // 必要に応じてサイズ更新を通知
  }}
>
  {({ index, style }) => (
    <div style={style}>Row {index}</div>
  )}
</VariableSizeList>

react-virtual はフック内でサイズを推定し、必要に応じて更新します。

  • 計測ロジックを自由に書けるため、複雑な条件にも対応可能です。
// react-virtual: 推定サイズと計測
const virtual = useVirtual({
  size: rows.length,
  parentRef,
  estimateSize: () => 50, // 推定値
  measureSize: (el) => el.getBoundingClientRect().height, // 実測ロジック
});

⚠️ 保守性と将来性

この点が最も重要な選定基準になります。

react-virtualized は事実上のレガシーです。

  • 作者が react-window への移行を公式に推奨しています。
  • バグ修正は行われますが、新機能は追加されません。
  • 新規プロジェクトでの使用は避けるべきです。

react-window は安定しており、広く使われています。

  • 作者によって積極的にメンテナンスされています。
  • React の最新バージョンとの互換性も保たれています。
  • 標準的なリスト表示なら、これが最も安全な選択です。

react-virtual はパッケージ名として非推奨です。

  • 機能は @tanstack/react-virtual へ引き継がれました。
  • フックベースの設計は現代的ですが、パッケージ名に注意が必要です。
  • -headless なアプローチが必要な場合のみ、新しい方を選択します。

📊 比較まとめ

特徴react-virtualizedreact-windowreact-virtual
提供形態完成コンポーネント軽量コンポーネントヘッドレスフック
保守状況レガシー(移行推奨)安定・維持中非推奨(TanStack へ)
API 難易度高い(複雑)低い(シンプル)中(自作要素あり)
柔軟性低い中高い
推奨度❌ 新規採用非推奨⭕ 標準的な選択⚠️ パッケージ名に注意

💡 最終的な推奨

react-window を第一選択としてください。

  • ほとんどのリスト表示ニーズを満たします。
  • 作者が保証しており、コミュニティも厚いです。
  • 実装がシンプルで、バグの入り込む隙が少ないです。

@tanstack/react-virtual (react-virtual の後継)を検討するのは以下の場合です。

  • React 以外のフレームワークともロジックを共有したい。
  • 独自の DOM 構造で仮想化を実装する必要がある。
  • 極めて特殊なスクロール挙動が求められる。

react-virtualized は使わないでください。

  • 既存プロジェクトの維持以外にメリットはありません。
  • 新規開発では技術的負債になります。

仮想化ライブラリの選択は、パフォーマンスと保守性のバランスです。標準的な道を選ぶなら react-window、特殊な制御が必要なら @tanstack/react-virtual、これが現代の正しい選び方です。

선택 방법: react-window vs react-virtualized vs react-virtual

  • react-window:

    React コンポーネントとして手軽に仮想化リストを実装したい場合に最適です。作者が react-virtualized の後継として設計しており、API がシンプルで学習コストが低いです。標準的なリストやグリッド表示であれば、これが第一選択肢になります。

  • react-virtualized:

    既存のレガシープロジェクトを維持する場合を除き、新しいプロジェクトでの使用は推奨しません。作者自身によって react-window への移行が勧められており、バンドルサイズが大きく API も複雑です。維持コストがかかるため、新規採用は避けるべきです。

  • react-virtual:

    このパッケージ名は非推奨であり、代わりに @tanstack/react-virtual を使用すべきです。フックを使ってレンダリングロジックを完全に制御したい場合に適しています。フレームワークに依存しないコアロジックが必要なら、新しい方のパッケージを検討してください。

react-window의 README

react-window logo

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

FAQs

Frequently asked questions can be found here.

Documentation

Documentation for this project is available at react-window.vercel.app.

List

Renders data with many rows.

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 list's current height (string)
  • function that returns the row height (in pixels) given an index and rowProps
  • dynamic row height cache returned by the useDynamicRowHeight hook

ℹ️ Percentage heights can't be resolved during server rendering unless a defaultHeight (or a pixel height via the style prop) is specified.

⚠️ 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 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 style prop).

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 display: none, or uses percentage row heights before its height has been measured), the offset is clamped or ignored and not retried. Specify a defaultHeight (or a pixel height via the style prop) when using percentage row heights.

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 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.

rowKey

Lists use the row index as a key by default. This prop can provide a custom key value.

ℹ️ 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 useCallback for this prop; do not use an inline function.

scrollElement

Element that scrolls the list, for lists that scroll along with other content (e.g. the page):

  • "window" to scroll with the page
  • an ancestor element that scrolls (e.g. stored with a useState ref callback); null until it has mounted

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).

  • scrollToRow scrolls the scroll element
  • defaultHeight is used as the viewport height until the scroll element has been measured (e.g. during server rendering)
  • percentage row heights are relative to the scroll element's viewport height
  • defaultScrollOffset is ignored

ℹ️ While the scroll element is null, the list renders the first rows (as it does during server rendering).

⚠️ The list itself doesn't scroll, so its onScroll handler isn't called; listen to the scroll element's "scroll" events instead (or use the useIsScrolling hook).

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

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.

Required props

NameDescription
cellComponent

React component responsible for rendering a cell.

This component will receive columnIndex, rowIndex, and style props 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 column width (in pixels) given an index and cellProps

ℹ️ Percentage widths can't be resolved during server rendering unless a defaultWidth (or a pixel width via the style prop) is specified.

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

ℹ️ Percentage heights can't be resolved during server rendering unless a defaultHeight (or a pixel height via the style prop) is specified.

Optional props

NameDescription
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 dir global attribute for more information.

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 key by default. This prop can be used along with the rowKey prop to provide a custom key value.

ℹ️ 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 useCallback for this prop; do not use an inline function.

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 style prop).

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 display: none, or uses percentage column widths before its width has been measured), the offset is clamped or ignored and not retried. Specify a defaultWidth (or a pixel width via the style prop) when using percentage column widths.

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 display: none, or uses percentage row heights before its height has been measured), the offset is clamped or ignored and not retried. Specify a defaultHeight (or a pixel height via the style prop) when using percentage row heights.

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 style prop).

gridRef

Imperative Grid API.

ℹ️ The useGridRef and useGridCallbackRef hooks are exported for convenience 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.

rowKey

Grids use the row index as a key by default. This prop can be used along with the columnKey prop to provide a custom key value.

ℹ️ 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 useCallback for this prop; do not use an inline function.

scrollElement

Element that scrolls the grid, for grids that scroll along with other content (e.g. the page):

  • "window" to scroll with the page
  • an ancestor element that scrolls (e.g. stored with a useState ref callback); null until it has mounted

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).

  • columns scroll with the scroll element too if the grid is as wide as its content (e.g. style={{ width: "max-content" }}); otherwise the grid fills the width of its parent and its columns scroll within it
  • scrollToCell, scrollToColumn and scrollToRow scroll whichever element scrolls each axis
  • defaultHeight and defaultWidth are used as the viewport size until the scroll element has been measured (e.g. during server rendering)
  • percentage row heights and column widths are relative to the scroll element's viewport
  • defaultScrollLeft and defaultScrollTop are ignored

ℹ️ While the scroll element is null, the grid renders the first rows (as it does during server rendering).

⚠️ The grid's onScroll handler is only called when the grid scrolls its own columns; listen to the scroll element's "scroll" events instead (or use the useIsScrolling hook).

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.