react-virtualized vs vue-virtual-scroller vs ngx-virtual-scroller vs react-window
虚拟滚动库
react-virtualizedvue-virtual-scrollerngx-virtual-scrollerreact-window类似的npm包:

虚拟滚动库

虚拟滚动库用于优化长列表或大数据集的渲染性能。通过只渲染可视区域内的元素,这些库显著减少了DOM节点的数量,从而提高了性能和用户体验。它们适用于需要高效处理大量数据的应用程序,尤其是在移动设备或性能受限的环境中。

npm下载趋势

3 年

GitHub Stars 排名

统计详情

npm包名称
下载量
Stars
大小
Issues
发布时间
License
react-virtualized1,354,08727,0842.24 MB11 年前MIT
vue-virtual-scroller339,83110,632166 kB2496 天前MIT
ngx-virtual-scroller7,254985-1536 年前MIT
react-window017,130209 kB21 个月前MIT

功能对比: react-virtualized vs vue-virtual-scroller vs ngx-virtual-scroller vs react-window

性能优化

  • react-virtualized:

    react-virtualized提供了多种优化技术,如窗口化和懒加载,确保在渲染大型列表时不会造成性能瓶颈。它支持复杂的布局和交互,适合需要高性能的应用。

  • vue-virtual-scroller:

    vue-virtual-scroller通过只渲染可见的列表项来提高性能,适合需要快速加载和滚动的Vue应用。它的实现简单,易于集成。

  • ngx-virtual-scroller:

    ngx-virtual-scroller通过只渲染可见的DOM元素来显著提高性能,尤其是在处理大量数据时。它利用Angular的变化检测机制,确保在数据变化时高效更新视图。

  • react-window:

    react-window是一个轻量级的虚拟化库,专注于性能。它通过减少渲染的组件数量来优化性能,适合大多数常见的虚拟滚动需求。

易用性

  • react-virtualized:

    react-virtualized功能丰富,但由于其复杂性,可能需要更多的学习和配置时间。适合需要高度自定义的开发者。

  • vue-virtual-scroller:

    vue-virtual-scroller的API简洁,易于使用,适合Vue开发者快速集成和实现虚拟滚动功能。

  • ngx-virtual-scroller:

    ngx-virtual-scroller提供了简单的API,易于与Angular项目集成。它的使用方式直观,适合快速上手。

  • react-window:

    react-window的API设计简单,易于理解和使用,适合快速开发和原型设计。

功能丰富性

  • react-virtualized:

    react-virtualized提供了多种组件和功能,如虚拟化表格、网格和复杂的滚动行为,适合复杂应用。

  • vue-virtual-scroller:

    vue-virtual-scroller提供了基本的虚拟滚动功能,适合简单的Vue应用。

  • ngx-virtual-scroller:

    ngx-virtual-scroller专注于基本的虚拟滚动功能,适合简单的列表场景。

  • react-window:

    react-window提供了基本的虚拟化功能,适合大多数常见场景,但功能相对较少。

社区支持

  • react-virtualized:

    react-virtualized拥有活跃的社区和丰富的文档,适合需要社区支持的开发者。

  • vue-virtual-scroller:

    vue-virtual-scroller的社区支持相对较新,但随着Vue的流行,正在逐渐增长。

  • ngx-virtual-scroller:

    ngx-virtual-scroller的社区相对较小,但在Angular生态系统中有一定的支持。

  • react-window:

    react-window是react-virtualized的轻量级替代品,社区支持良好,适合快速开发。

适用场景

  • react-virtualized:

    适用于需要复杂列表和表格布局的React应用,特别是需要高性能和灵活性的场景。

  • vue-virtual-scroller:

    适用于Vue.js应用中需要实现虚拟滚动的场景,特别是当需要快速开发时。

  • ngx-virtual-scroller:

    适用于Angular项目中需要处理长列表的场景,特别是当数据量较大时。

  • react-window:

    适用于大多数常见的虚拟滚动需求,尤其是当性能是主要考虑因素时。

如何选择: react-virtualized vs vue-virtual-scroller vs ngx-virtual-scroller vs react-window

  • react-virtualized:

    选择react-virtualized如果你需要一个功能丰富的解决方案,支持复杂的列表和表格布局。它提供了多种组件和功能,如虚拟化表格、网格和滚动条,适合需要高度自定义的场景。

  • vue-virtual-scroller:

    选择vue-virtual-scroller如果你正在使用Vue.js,并且需要一个简单的虚拟滚动解决方案。它易于集成,并且与Vue的响应式系统兼容,适合快速开发。

  • ngx-virtual-scroller:

    选择ngx-virtual-scroller如果你正在使用Angular,并且需要一个轻量级的解决方案来处理长列表。它与Angular的变化检测机制紧密集成,提供了简单易用的API。

  • react-window:

    选择react-window如果你需要一个轻量级的虚拟化解决方案,且对性能有较高要求。它的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.