React Window

2.2.7 · active · verified Sun Apr 19

react-window is a highly performant and minimalist React component library for efficiently rendering large lists and grid data using windowing (also known as virtualization). It optimizes performance by rendering only the items currently visible within the viewport, significantly reducing the DOM nodes, memory footprint, and rendering time compared to rendering all items in a large dataset. The library provides several specialized components, including `FixedSizeList`, `VariableSizeList`, `FixedSizeGrid`, and `VariableSizeGrid`, to cater to different use cases like lists with fixed item sizes or dynamic item sizes. The current stable version is 2.2.7, and it maintains an active release cadence, frequently publishing patch versions to address bugs and enhance TypeScript compatibility, especially for newer React versions. Its key differentiators include a small bundle size, strong focus on performance, and a straightforward API, making it a popular choice for optimizing UI rendering in applications and development tools like React DevTools.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates a basic setup of `FixedSizeList` to efficiently render 1000 rows, each with a fixed height, within a scrollable container.

import React from 'react';
import { FixedSizeList } from 'react-window';
import { createRoot } from 'react-dom/client';

const Row = ({ index, style }) => {
  // `style` prop is crucial for positioning items correctly
  return (
    <div style={{ ...style, background: index % 2 ? '#eee' : 'white', padding: '10px' }}>
      Item {index + 1}
    </div>
  );
};

const MyVirtualList = () => (
  <FixedSizeList
    height={300} // Total height of the scrollable container
    width={400}  // Total width of the scrollable container
    itemCount={1000} // Total number of items in the list
    itemSize={50}  // Height of each item
  >
    {Row}
  </FixedSizeList>
);

const container = document.getElementById('root');
if (container) {
  const root = createRoot(container);
  root.render(<MyVirtualList />);
}

view raw JSON →