react-window vs react-virtualized vs react-virtual
React 虚拟化库
react-windowreact-virtualizedreact-virtual类似的npm包:

React 虚拟化库

React 虚拟化库用于高效地渲染大型列表或表格,以提高性能并减少内存使用。这些库通过仅渲染可视区域内的元素来优化渲染过程,从而避免一次性渲染所有数据,特别适合处理大量数据的场景。它们在用户界面中提供流畅的滚动体验,并减少了 DOM 节点的数量,从而提升了性能和响应速度。

npm下载趋势

3 年

GitHub Stars 排名

统计详情

npm包名称
下载量
Stars
大小
Issues
发布时间
License
react-window4,716,13517,107209 kB118 天前MIT
react-virtualized1,512,74127,0792.24 MB11 年前MIT
react-virtual490,1656,734158 kB113-MIT

功能对比: react-window vs react-virtualized vs react-virtual

性能优化

  • react-window:

    react-window 通过使用简单的 API 和轻量级的实现,确保在渲染大量列表时具有极高的性能,适合需要快速滚动的场景。

  • react-virtualized:

    react-virtualized 提供了多种性能优化技术,如窗口化和懒加载,确保在处理大量数据时仍能保持流畅的用户体验。

  • react-virtual:

    react-virtual 通过只渲染可见区域的元素来优化性能,减少了 DOM 操作的数量,从而提高了渲染速度。

功能丰富性

  • react-window:

    react-window 提供基本的虚拟化功能,专注于性能,适合不需要复杂功能的应用。

  • react-virtualized:

    react-virtualized 是一个功能全面的库,支持复杂的列表、表格、排序、过滤等多种功能,适合需要高度自定义的应用。

  • react-virtual:

    react-virtual 提供基本的虚拟化功能,适合简单的列表场景,但不支持复杂的功能。

学习曲线

  • react-window:

    react-window 的学习曲线也较为平缓,简单易用,适合快速集成。

  • react-virtualized:

    react-virtualized 的学习曲线较陡峭,功能丰富,可能需要更多时间来掌握其复杂性。

  • react-virtual:

    react-virtual 的学习曲线相对较平缓,特别适合初学者,易于上手。

社区支持

  • react-window:

    react-window 的社区也在不断增长,提供了良好的文档和支持,适合快速开发。

  • react-virtualized:

    react-virtualized 拥有一个活跃的社区,提供丰富的文档、示例和支持,适合需要社区帮助的开发者。

  • react-virtual:

    react-virtual 的社区相对较小,但仍然提供了基本的文档和支持。

灵活性与扩展性

  • react-window:

    react-window 提供了简单的 API,适合快速开发,但扩展性相对较低,适合不需要复杂定制的项目。

  • react-virtualized:

    react-virtualized 提供了丰富的功能和选项,允许开发者根据项目需求进行深度定制和扩展。

  • react-virtual:

    react-virtual 提供了灵活的 API,允许开发者根据需要进行扩展,适合需要高度定制的项目。

如何选择: react-window vs react-virtualized vs react-virtual

  • react-window:

    选择 react-window 如果你需要一个更小、更高效的库,专注于性能,且只需基本的虚拟化功能。它是 react-virtualized 的轻量级替代品,适合于对性能要求较高的应用。

  • react-virtualized:

    选择 react-virtualized 如果你需要一个功能丰富的库,支持复杂的列表和表格,提供多种功能如排序、过滤和分组。它适合于需要高度自定义和多功能的应用程序。

  • react-virtual:

    选择 react-virtual 如果你需要一个轻量级的解决方案,专注于简单的虚拟化功能,并且希望使用 hooks 来实现更灵活的组件设计。它适合于需要快速集成的项目。

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.