react-window vs react-virtualized vs react-infinite-scroll-component vs react-tiny-virtual-list
React 虚拟化和无限滚动库
react-windowreact-virtualizedreact-infinite-scroll-componentreact-tiny-virtual-list类似的npm包:

React 虚拟化和无限滚动库

在现代 web 开发中,处理大量数据时,性能和用户体验至关重要。这些库提供了高效的方式来渲染长列表或无限滚动内容,确保在用户滚动时不会造成性能瓶颈。通过虚拟化技术,这些库只渲染可视区域内的元素,从而显著提高性能并减少内存使用。选择合适的库可以帮助开发者在不同的场景中实现最佳的用户体验。

npm下载趋势

3 年

GitHub Stars 排名

统计详情

npm包名称
下载量
Stars
大小
Issues
发布时间
License
react-window4,716,13517,106209 kB118 天前MIT
react-virtualized1,512,74127,0792.24 MB11 年前MIT
react-infinite-scroll-component1,017,8163,064169 kB2003 个月前MIT
react-tiny-virtual-list118,4372,497-548 年前MIT

功能对比: react-window vs react-virtualized vs react-infinite-scroll-component vs react-tiny-virtual-list

性能优化

  • react-window:

    在性能上进行了优化,专注于简化 API,适合大多数虚拟化需求,性能表现良好,且易于使用。

  • react-virtualized:

    提供了多种虚拟化策略,支持复杂数据结构和大量数据,性能优化非常全面,适合需要高性能和复杂交互的应用。

  • react-infinite-scroll-component:

    该组件通过监听滚动事件来实现无限滚动,适合简单的列表,性能表现良好,但在处理大量数据时可能会出现性能瓶颈。

  • react-tiny-virtual-list:

    通过虚拟化技术,仅渲染可视区域内的列表项,极大地提高了性能,特别是在处理动态高度的列表时表现优异。

易用性

  • react-window:

    提供了简单的 API,易于理解和使用,适合大多数开发者,尤其是需要快速实现虚拟化的场景。

  • react-virtualized:

    功能丰富但学习曲线较陡,适合需要深入定制和复杂功能的开发者,可能需要更多的时间来掌握。

  • react-infinite-scroll-component:

    该组件易于使用,提供简单的 API,适合快速集成和开发,适合初学者和小型项目。

  • react-tiny-virtual-list:

    API 简洁明了,适合快速上手,特别是对于需要动态高度的列表,使用简单。

功能丰富性

  • react-window:

    功能较为简单,专注于虚拟化,适合大多数常见需求,但不如 react-virtualized 功能丰富。

  • react-virtualized:

    功能非常丰富,支持排序、过滤、虚拟化等多种功能,适合复杂的数据展示需求。

  • react-infinite-scroll-component:

    专注于无限滚动功能,功能相对简单,适合基本需求,不支持复杂的列表交互。

  • react-tiny-virtual-list:

    支持动态高度,适合需要灵活布局的场景,功能相对简单,适合小型项目。

社区支持与维护

  • react-window:

    社区活跃,维护良好,文档清晰,适合大多数开发者使用。

  • react-virtualized:

    社区庞大,文档详细,更新频繁,适合需要长期维护和支持的项目。

  • react-infinite-scroll-component:

    社区活跃,文档齐全,适合快速上手和解决问题。

  • react-tiny-virtual-list:

    社区相对较小,但维护良好,适合轻量级项目。

灵活性与扩展性

  • react-window:

    灵活性较好,适合大多数常见需求,易于与其他库结合使用。

  • react-virtualized:

    高度可定制,支持多种功能扩展,适合复杂应用的开发。

  • react-infinite-scroll-component:

    扩展性有限,主要用于简单的无限滚动场景,适合快速实现。

  • react-tiny-virtual-list:

    灵活性较高,支持动态高度,适合需要自定义布局的场景。

如何选择: react-window vs react-virtualized vs react-infinite-scroll-component vs react-tiny-virtual-list

  • react-window:

    选择 react-window 如果你需要一个更轻量的替代方案,专注于性能和简单性,适合大多数常见的虚拟化需求。

  • react-virtualized:

    选择 react-virtualized 如果你需要一个功能丰富且高度可定制的库,适合复杂的列表和表格,支持多种功能如排序、过滤和虚拟化。

  • react-infinite-scroll-component:

    选择 react-infinite-scroll-component 如果你需要实现简单的无限滚动功能,且希望快速集成,适合小型项目或简单的列表展示。

  • react-tiny-virtual-list:

    选择 react-tiny-virtual-list 如果你需要一个轻量级的解决方案,支持动态高度的列表,适合需要灵活布局的场景。

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; version 1.x documentation can be found at react-window-v1.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 grid's current height (string)
  • function that returns the row height (in pixels) given an index and cellProps
  • dynamic row height cache returned by the useDynamicRowHeight hook

⚠️ 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 cells). This property can be used to render things like overlays or tooltips.

defaultHeight

Default height of list for initial render. This value is important for server rendering.

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

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 an index and style prop 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
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

Optional props

NameDescription
className

CSS class name.

dir

Indicates the directionality of grid cells.

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

defaultHeight

Default height of grid for initial render. This value is important for server rendering.

defaultWidth

Default width of grid for initial render. This value is important for server rendering.

gridRef

Imperative Grid API.

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

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.