react-virtualized vs react-infinite vs react-infinite-scroll-component vs react-window
React 無限滾動和虛擬化庫
react-virtualizedreact-infinitereact-infinite-scroll-componentreact-window類似パッケージ:

React 無限滾動和虛擬化庫

這些庫旨在幫助開發者在 React 應用中實現高效的無限滾動和虛擬化功能。無限滾動允許用戶在滾動時動態加載更多內容,從而提升用戶體驗和性能。虛擬化則是通過只渲染可見的元素來減少 DOM 節點的數量,從而提高性能,特別是在處理大量數據時。這些庫各有特點,適用於不同的使用場景和需求。

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

3 年

GitHub Starsランキング

統計詳細

パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
react-virtualized1,723,75827,0671.31 MB18日前MIT
react-infinite14,9762,682243 kB101-BSD-3-Clause
react-infinite-scroll-component03,091217 kB1385ヶ月前MIT
react-window017,200417 kB03分前MIT

機能比較: react-virtualized vs react-infinite vs react-infinite-scroll-component vs react-window

無限滾動功能

  • react-virtualized:

    react-virtualized 主要專注於虛擬化,無限滾動功能是其附加特性,適合需要高性能渲染的數據密集型應用。

  • react-infinite:

    react-infinite 提供了基本的無限滾動功能,允許用戶在滾動時自動加載更多內容,適合小型應用或簡單的列表展示。

  • react-infinite-scroll-component:

    react-infinite-scroll-component 提供了更靈活的無限滾動功能,支持多種加載狀態和滾動行為的控制,適合需要更高自定義的應用。

  • react-window:

    react-window 提供簡單的無限滾動支持,專注於性能和輕量化,適合需要快速渲染的場景。

性能優化

  • react-virtualized:

    react-virtualized 是性能優化的佼佼者,能夠有效渲染大量數據,適合數據密集型應用。

  • react-infinite:

    react-infinite 在性能上表現良好,但在處理大量數據時可能會遇到瓶頸,適合小型項目。

  • react-infinite-scroll-component:

    react-infinite-scroll-component 提供了更好的性能優化選項,能夠有效管理加載狀態,適合中型項目。

  • react-window:

    react-window 專注於性能,能夠快速渲染大量元素,適合需要高效渲染的場景。

學習曲線

  • react-virtualized:

    react-virtualized 的學習曲線較陡,需要理解虛擬化的概念,適合有經驗的開發者。

  • react-infinite:

    react-infinite 的學習曲線相對較平緩,易於上手,適合初學者。

  • react-infinite-scroll-component:

    react-infinite-scroll-component 也相對容易學習,提供了清晰的文檔和範例,適合中級開發者。

  • react-window:

    react-window 的學習曲線較低,易於理解和使用,適合所有級別的開發者。

組件靈活性

  • react-virtualized:

    react-virtualized 提供多種虛擬化組件,靈活性高,適合複雜的數據展示需求。

  • react-infinite:

    react-infinite 提供基本的組件靈活性,適合簡單的應用需求。

  • react-infinite-scroll-component:

    react-infinite-scroll-component 提供更高的組件靈活性,允許開發者自定義加載行為和樣式,適合中型項目。

  • react-window:

    react-window 提供簡單的組件靈活性,專注於性能,適合快速開發。

社區支持

  • react-virtualized:

    react-virtualized 擁有強大的社區支持和豐富的文檔,適合需要深入學習的開發者。

  • react-infinite:

    react-infinite 的社區支持相對較小,更新頻率較低。

  • react-infinite-scroll-component:

    react-infinite-scroll-component 擁有活躍的社區支持,文檔齊全,更新頻繁。

  • react-window:

    react-window 也有良好的社區支持,文檔清晰,適合快速上手。

選び方: react-virtualized vs react-infinite vs react-infinite-scroll-component vs react-window

  • react-virtualized:

    選擇 react-virtualized 如果你需要處理大量數據並且希望優化性能。這個庫提供了多種虛擬化組件,能夠有效地渲染大量列表和表格,適合數據密集型應用。

  • react-infinite:

    選擇 react-infinite 如果你需要一個簡單的無限滾動解決方案,並且希望快速集成到現有的 React 應用中。這個庫提供了基本的無限滾動功能,適合小型項目或快速原型開發。

  • react-infinite-scroll-component:

    選擇 react-infinite-scroll-component 如果你需要更靈活的無限滾動解決方案,並且希望能夠輕鬆地控制加載狀態和滾動行為。這個庫提供了更多的配置選項,適合中型到大型項目。

  • react-window:

    選擇 react-window 如果你需要一個更輕量級的虛擬化解決方案。這個庫專注於性能和簡單性,適合需要快速渲染大量元素的場景。

react-virtualized のREADME

React virtualized

React components for efficiently rendering large lists and tabular data. Check out the documentation for live 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.

Getting started

Install react-virtualized using npm.

npm install react-virtualized --save

ES module and CommonJS builds are included, along with TypeScript type definitions. 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';

The package is marked as side-effect free (other than its CSS), so bundlers will tree-shake any components you don't use.

TypeScript types are exported for each component's props (e.g. ListProps, GridProps, TableProps) along with the parameters passed to renderers (e.g. RowRendererParams, CellRendererParams, TableCellProps).

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 are wrapped in memo 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

This shallow comparison will detect changes to any props, even ones a component doesn't use. 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 components can be forcefully re-rendered by calling forceUpdate on their ref. 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

Documentation and live examples for every component are available at react-virtualized-docs.vercel.app.

Components:

CellMeasurer measures cells whose sizes aren't known ahead of time.

Grid, List, Masonry and Table can also be scrolled by the window (or another scrollable element) with the scrollElement prop.

Higher-order components:

[!NOTE] AutoSizer is no longer part of react-virtualized (as of version 10); it is available as the separate react-virtualized-auto-sizer package. See sizing components for how to use it with react-virtualized.

There are also a couple of how-to guides:

Examples

Here are some "recipe" type demos:

Supported Browsers

react-virtualized aims to support all evergreen browsers and recent mobile browsers for iOS and Android.

If you find a browser-specific problem, please report it along with a repro case (e.g. a CodeSandbox).

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.