Top Related Projects
🤖 Headless UI for Virtualizing Large Element Lists in JS/TS, React, Solid, Vue and Svelte
React components for efficiently rendering large lists and tabular data
The most powerful virtual list component for React
🤖 Headless UI for Virtualizing Large Element Lists in JS/TS, React, Solid, Vue and Svelte
A tiny but mighty 3kb list virtualization library, with zero dependencies 💪 Supports variable heights/widths, sticky items, scrolling to index, and more!
Quick Overview
React Window is a lightweight, efficient windowing library for React applications. It enables rendering large lists and tabular data with improved performance by only rendering visible items. This library is particularly useful for handling large datasets in web applications.
Pros
- Significantly improves performance for large lists and grids
- Supports both fixed-size and variable-size lists and grids
- Lightweight and has minimal dependencies
- Easy to integrate with existing React applications
Cons
- Limited built-in features compared to some other windowing libraries
- May require additional configuration for complex use cases
- Learning curve for developers new to windowing concepts
- Some edge cases might require custom implementations
Code Examples
- Basic fixed-size list:
import { FixedSizeList } from 'react-window';
const Row = ({ index, style }) => (
<div style={style}>Row {index}</div>
);
const Example = () => (
<FixedSizeList
height={150}
itemCount={1000}
itemSize={35}
width={300}
>
{Row}
</FixedSizeList>
);
- Variable-size grid:
import { VariableSizeGrid } from 'react-window';
const Cell = ({ columnIndex, rowIndex, style }) => (
<div style={style}>
Item {rowIndex},{columnIndex}
</div>
);
const Example = () => (
<VariableSizeGrid
columnCount={1000}
columnWidth={index => (index % 3 === 0 ? 100 : 50)}
height={150}
rowCount={1000}
rowHeight={index => (index % 2 === 0 ? 50 : 30)}
width={300}
>
{Cell}
</VariableSizeGrid>
);
- Using with dynamic content:
import { FixedSizeList } from 'react-window';
import AutoSizer from 'react-virtualized-auto-sizer';
const Row = ({ index, style, data }) => (
<div style={style}>{data[index]}</div>
);
const Example = ({ items }) => (
<AutoSizer>
{({ height, width }) => (
<FixedSizeList
height={height}
itemCount={items.length}
itemSize={35}
width={width}
itemData={items}
>
{Row}
</FixedSizeList>
)}
</AutoSizer>
);
Getting Started
-
Install the package:
npm install react-window
-
Import and use in your React component:
import { FixedSizeList } from 'react-window'; const MyList = () => ( <FixedSizeList height={400} width={300} itemSize={50} itemCount={1000} > {({ index, style }) => ( <div style={style}>Row {index}</div> )} </FixedSizeList> );
-
Customize as needed for your specific use case, considering different list types (FixedSizeList, VariableSizeList) or grid components (FixedSizeGrid, VariableSizeGrid) based on your requirements.
Competitor Comparisons
🤖 Headless UI for Virtualizing Large Element Lists in JS/TS, React, Solid, Vue and Svelte
Pros of Virtual
- Framework-agnostic, supporting React, Vue, Solid, and more
- More flexible API with advanced features like dynamic item sizes and sticky items
- Active development and community support
Cons of Virtual
- Steeper learning curve due to more complex API
- Potentially larger bundle size due to additional features
Code Comparison
React Window:
import { FixedSizeList } from 'react-window';
const Example = () => (
<FixedSizeList
height={150}
itemCount={1000}
itemSize={35}
width={300}
>
{({ index, style }) => <div style={style}>Row {index}</div>}
</FixedSizeList>
);
Virtual:
import { useVirtualizer } from '@tanstack/react-virtual';
const Example = () => {
const virtualizer = useVirtualizer({
count: 1000,
getScrollElement: () => parentRef.current,
estimateSize: () => 35,
});
return (
<div ref={parentRef} style={{ height: '150px', overflow: 'auto' }}>
<div style={{ height: `${virtualizer.getTotalSize()}px` }}>
{virtualizer.getVirtualItems().map((virtualItem) => (
<div key={virtualItem.key} style={{
position: 'absolute',
top: 0,
left: 0,
width: '100%',
height: `${virtualItem.size}px`,
transform: `translateY(${virtualItem.start}px)`,
}}>
Row {virtualItem.index}
</div>
))}
</div>
</div>
);
};
React components for efficiently rendering large lists and tabular data
Pros of react-virtualized
- More comprehensive feature set, including support for various layouts (Grid, List, Table, etc.)
- Offers additional utilities like CellMeasurer for dynamic content sizing
- Mature project with extensive documentation and community support
Cons of react-virtualized
- Larger bundle size due to its comprehensive nature
- More complex API, which can lead to a steeper learning curve
- Higher memory usage, especially for large datasets
Code Comparison
react-virtualized:
import { List } from 'react-virtualized';
<List
width={300}
height={300}
rowCount={1000}
rowHeight={20}
rowRenderer={({ index, key, style }) => (
<div key={key} style={style}>Row {index}</div>
)}
/>
react-window:
import { FixedSizeList } from 'react-window';
<FixedSizeList
height={300}
width={300}
itemCount={1000}
itemSize={20}
>
{({ index, style }) => <div style={style}>Row {index}</div>}
</FixedSizeList>
Both libraries serve similar purposes, but react-window is a more lightweight and focused alternative to react-virtualized. It offers improved performance and a simpler API, making it easier to use for basic virtualization needs. However, react-virtualized remains a powerful choice for complex use cases requiring advanced features and layouts.
The most powerful virtual list component for React
Pros of react-virtuoso
- More flexible and feature-rich, supporting dynamic heights and complex layouts
- Built-in support for grouping, sticky headers, and footer
- Easier to use with less boilerplate code required
Cons of react-virtuoso
- Slightly larger bundle size due to additional features
- May have a steeper learning curve for simpler use cases
- Less established in the React ecosystem compared to react-window
Code Comparison
react-window:
import { FixedSizeList } from 'react-window';
<FixedSizeList
height={400}
itemCount={1000}
itemSize={35}
width={300}
>
{({ index, style }) => <div style={style}>Row {index}</div>}
</FixedSizeList>
react-virtuoso:
import { Virtuoso } from 'react-virtuoso';
<Virtuoso
style={{ height: '400px', width: '300px' }}
totalCount={1000}
itemContent={index => <div>Row {index}</div>}
/>
Both libraries aim to efficiently render large lists in React applications, but react-virtuoso offers more built-in features and flexibility at the cost of a slightly larger bundle size. react-window is more lightweight and may be preferable for simpler use cases, while react-virtuoso shines in complex scenarios with dynamic content and layouts.
🤖 Headless UI for Virtualizing Large Element Lists in JS/TS, React, Solid, Vue and Svelte
Pros of Virtual
- Framework-agnostic, supporting React, Vue, Solid, and more
- More flexible API with advanced features like dynamic item sizes and sticky items
- Active development and community support
Cons of Virtual
- Steeper learning curve due to more complex API
- Potentially larger bundle size due to additional features
Code Comparison
React Window:
import { FixedSizeList } from 'react-window';
const Example = () => (
<FixedSizeList
height={150}
itemCount={1000}
itemSize={35}
width={300}
>
{({ index, style }) => <div style={style}>Row {index}</div>}
</FixedSizeList>
);
Virtual:
import { useVirtualizer } from '@tanstack/react-virtual';
const Example = () => {
const virtualizer = useVirtualizer({
count: 1000,
getScrollElement: () => parentRef.current,
estimateSize: () => 35,
});
return (
<div ref={parentRef} style={{ height: '150px', overflow: 'auto' }}>
<div style={{ height: `${virtualizer.getTotalSize()}px` }}>
{virtualizer.getVirtualItems().map((virtualItem) => (
<div key={virtualItem.key} style={{
position: 'absolute',
top: 0,
left: 0,
width: '100%',
height: `${virtualItem.size}px`,
transform: `translateY(${virtualItem.start}px)`,
}}>
Row {virtualItem.index}
</div>
))}
</div>
</div>
);
};
A tiny but mighty 3kb list virtualization library, with zero dependencies 💪 Supports variable heights/widths, sticky items, scrolling to index, and more!
Pros of react-tiny-virtual-list
- Smaller bundle size, making it more lightweight for simpler use cases
- Easier to set up and use for basic virtualization needs
- Supports both fixed and variable height items out of the box
Cons of react-tiny-virtual-list
- Less actively maintained compared to react-window
- Fewer features and customization options
- Limited support for horizontal lists and grid layouts
Code Comparison
react-tiny-virtual-list:
import VirtualList from 'react-tiny-virtual-list';
<VirtualList
width={300}
height={600}
itemCount={10000}
itemSize={50}
renderItem={({ index, style }) => (
<div style={style}>Item {index}</div>
)}
/>
react-window:
import { FixedSizeList } from 'react-window';
<FixedSizeList
height={600}
width={300}
itemCount={10000}
itemSize={50}
>
{({ index, style }) => (
<div style={style}>Item {index}</div>
)}
</FixedSizeList>
Both libraries offer similar basic functionality for rendering large lists efficiently. react-tiny-virtual-list provides a simpler API, while react-window offers more advanced features and better performance for complex use cases. The choice between them depends on the specific requirements of your project and the level of customization needed.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
react-window
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
Documentation
Documentation for this project is available at react-window.vercel.app.
Note: Older version 1.x documentation can be found at react-window-v1.vercel.app or on the NPM page for a specific version, e.g. 1.8.11.)
TypeScript types
TypeScript definitions are included within the published dist
folder
Top Related Projects
🤖 Headless UI for Virtualizing Large Element Lists in JS/TS, React, Solid, Vue and Svelte
React components for efficiently rendering large lists and tabular data
The most powerful virtual list component for React
🤖 Headless UI for Virtualizing Large Element Lists in JS/TS, React, Solid, Vue and Svelte
A tiny but mighty 3kb list virtualization library, with zero dependencies 💪 Supports variable heights/widths, sticky items, scrolling to index, and more!
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot