react-window vs react-virtualized vs react-list vs react-tiny-virtual-list vs react-infinite
React 用仮想スクロールライブラリの技術比較
react-windowreact-virtualizedreact-listreact-tiny-virtual-listreact-infinite유사 패키지:

React 用仮想スクロールライブラリの技術比較

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 はよりシンプルな実装を目指していますが、機能性やメンテナンス状況に違いがあります。

npm 다운로드 트렌드

3 년

GitHub Stars 순위

통계 세부사항

패키지
다운로드
Stars
크기
Issues
발행일
라이선스
react-window8,481,69417,212428 kB15日前MIT
react-virtualized2,262,03727,0671.31 MB119日前MIT
react-list651,5131,97035.3 kB724ヶ月前MIT
react-tiny-virtual-list140,3272,483-558年前MIT
react-infinite10,1032,682243 kB101-BSD-3-Clause

React 用仮想スクロールライブラリ:実装とパフォーマンスの深層比較

大量のデータを扱う 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>
    )}
  />
);

📦 無限ロード(Infinity Loading)の実装

データがページネーションされている場合、スクロールに合わせて追加でデータを読み込む必要があります。この実装方法もライブラリによって異なります。

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-windowreact-virtualizedreact-infinitereact-listreact-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 vs react-virtualized vs react-list vs react-tiny-virtual-list vs react-infinite

  • react-window:

    新規プロジェクトでは react-window を首选してください。同じ作者によって react-virtualized の課題を解決するために作られており、バンドルサイズが小さく、API もシンプルです。メンテナンスが活発で、現在の React エコシステムにおける事実上の標準です。

  • react-virtualized:

    既存のレガシープロジェクトで既に導入されている場合はそのまま使い続けても問題ありません。しかし、新規プロジェクトでの採用は避けるべきです。機能は豊富ですが、サイズが大きく、API が複雑で、現在はメンテナンスモードに入っています。

  • react-list:

    非常にシンプルな実装で、依存関係を最小限に抑えたい場合に適しています。しかし、機能が少ないため、複雑なレイアウトや高度な最適化が必要なプロジェクトには不向きです。

  • react-tiny-virtual-list:

    バンドルサイズを極限まで小さくしたい場合の選択肢ですが、メンテナンスが停止している可能性が高く、機能も限定的です。長期のプロジェクトでは react-window の方が安全です。

  • react-infinite:

    単純な「無限スクロール」実装のみが必要で、仮想化(DOM ノードの再利用)が必須でない場合に検討します。ただし、メンテナンス状況が不明確なことが多く、大規模なリストではパフォーマンス劣化のリスクがあるため、react-window の InfiniteLoader との併用を推奨します。

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.

ℹ️ Spread ariaAttributes onto the row element; they identify it as a row (e.g. so that dynamic row heights are measured reliably)

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