Scripts2026年5月29日·1 分钟阅读

React Window — Efficiently Render Large Lists and Grids in React

A lightweight React library for virtualizing long lists and tabular data by only rendering visible items in the viewport.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
React Window Overview
直接安装命令
npx -y tokrepo@latest install 3ddf5178-5af3-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

Introduction

React Window is a rewrite of react-virtualized by the same author, focused on being smaller and faster. It solves the problem of rendering thousands of rows or grid cells without degrading scroll performance, by only mounting the DOM nodes currently visible in the viewport plus a small overscan buffer.

What React Window Does

  • Virtualizes fixed-size and variable-size vertical lists
  • Virtualizes fixed-size and variable-size grids (rows and columns)
  • Renders only visible items plus a configurable overscan count
  • Passes precise positioning styles to each row or cell component
  • Supports scrolling to a specific item index programmatically

Architecture Overview

React Window maintains an internal offset state that tracks the scroll position. On each scroll event it recalculates which item indices fall within the visible range, adds an overscan buffer, and renders only those items as absolutely positioned children inside a scrollable container. For variable-size lists, an item-size function is called per index. The outer container handles native scroll; the inner container is sized to the total content height to preserve scrollbar fidelity.

Installation & Configuration

  • Install via npm: npm install react-window
  • Choose the right component: FixedSizeList, VariableSizeList, FixedSizeGrid, or VariableSizeGrid
  • Set height, width, itemCount, and itemSize (number or function) as props
  • Use the overscanCount prop to control how many off-screen items to pre-render
  • Pair with react-window-infinite-loader for paginated or lazy-loaded data

Key Features

  • Extremely small bundle size (under 6 KB gzipped)
  • Fixed and variable item size support for both lists and grids
  • RTL (right-to-left) layout support
  • Compatible with react-window-infinite-loader for infinite scrolling
  • Render prop pattern gives full control over item markup and styling

Comparison with Similar Tools

  • react-virtualized — predecessor by the same author; more features but significantly larger bundle
  • TanStack Virtual — framework-agnostic headless virtualizer; supports React, Vue, Solid, and Svelte
  • react-virtuoso — higher-level API with grouped items and auto-sizing; larger bundle
  • @tanstack/react-virtual — hooks-based API; newer approach with measured item sizes
  • react-infinite-scroll-component — simpler infinite scroll but no true virtualization

FAQ

Q: When should I use VariableSizeList instead of FixedSizeList? A: Use VariableSizeList when rows have different heights. You must provide an itemSize function that returns the pixel height for each index.

Q: Can I use React Window with dynamic content that changes height? A: VariableSizeList supports it, but you need to call resetAfterIndex when item sizes change so the cache is invalidated.

Q: Does it work with SSR frameworks like Next.js? A: Yes. The component renders an empty shell on the server and hydrates on the client since virtualization depends on scroll position.

Q: How does it compare to react-virtualized in performance? A: React Window is faster to load due to its smaller size and is slightly more efficient at runtime because it removed features rarely used in practice.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产