react-window vs react-virtualized vs react-infinite-scroll-component vs react-list
React 列表渲染库
react-windowreact-virtualizedreact-infinite-scroll-componentreact-list类似的npm包:

React 列表渲染库

在 React 开发中,列表渲染是一个常见的需求,尤其是在处理大量数据时。为了提高性能和用户体验,开发者可以使用不同的库来实现高效的列表渲染。这些库提供了不同的功能和设计理念,以适应不同的应用场景。选择合适的库可以帮助开发者更好地管理数据的渲染和滚动行为,从而提升整体应用的性能和用户体验。

npm下载趋势

3 年

GitHub Stars 排名

统计详情

npm包名称
下载量
Stars
大小
Issues
发布时间
License
react-window4,697,96917,104209 kB115 天前MIT
react-virtualized1,508,58927,0792.24 MB11 年前MIT
react-infinite-scroll-component992,9343,064169 kB2003 个月前MIT
react-list476,6791,97434.9 kB711 年前MIT

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

性能优化

  • react-window:

    是 react-virtualized 的轻量级替代品,专注于简单的列表和网格,性能优越,适合大多数常见场景。

  • react-virtualized:

    提供了多种虚拟化技术,包括列表和表格的虚拟化,能够处理数千甚至数万条数据,性能极佳。

  • react-infinite-scroll-component:

    该组件通过监听滚动事件来实现无限滚动,适合小型数据集,性能较好,但在数据量极大时可能会出现性能瓶颈。

  • react-list:

    通过只渲染可视区域内的列表项来优化性能,适合中等规模的数据集,能够有效减少 DOM 节点的数量。

易用性

  • react-window:

    设计简洁,易于使用,适合初学者和需要快速实现虚拟化的开发者。

  • react-virtualized:

    功能强大但学习曲线较陡,适合有经验的开发者,提供了丰富的配置选项。

  • react-infinite-scroll-component:

    使用简单,配置方便,适合快速开发和原型设计,文档清晰,易于上手。

  • react-list:

    API 简洁明了,适合中级开发者,能够快速实现基本的列表功能。

功能特性

  • react-window:

    专注于列表和网格的虚拟化,提供基本的功能,适合大多数常见需求。

  • react-virtualized:

    支持复杂的布局和多种数据展示形式,包括表格、列表、网格等,功能丰富。

  • react-infinite-scroll-component:

    支持无限滚动和加载更多功能,适合动态数据加载场景。

  • react-list:

    支持简单的列表渲染,提供了基本的虚拟化功能,适合简单场景。

社区支持

  • react-window:

    相对较新,但社区正在快速增长,文档简单易懂,适合新手。

  • react-virtualized:

    拥有广泛的社区支持和丰富的文档,但由于功能复杂,可能需要更多的学习时间。

  • react-infinite-scroll-component:

    社区活跃,提供了多种示例和使用案例,适合快速上手。

  • react-list:

    社区支持良好,文档清晰,能够找到许多使用示例。

灵活性

  • react-window:

    灵活性适中,适合大多数常见场景,但不支持复杂的自定义需求。

  • react-virtualized:

    极高的灵活性,支持多种复杂场景,适合需要高度自定义的应用。

  • react-infinite-scroll-component:

    灵活性较低,主要用于无限滚动场景,适合特定用途。

  • react-list:

    提供了一定的灵活性,适合简单的列表展示,但功能有限。

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

  • react-window:

    选择 react-window 如果你需要轻量级的虚拟化解决方案,适合简单的列表和网格布局,性能优越且易于使用。

  • react-virtualized:

    选择 react-virtualized 如果你需要强大的功能和灵活性,适合处理大规模数据集,支持复杂的列表和表格布局。

  • react-infinite-scroll-component:

    选择 react-infinite-scroll-component 如果你需要简单易用的无限滚动功能,适合小型项目或快速原型开发。

  • react-list:

    选择 react-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.