Virtualization with react-window (Legacy)
You'll learn about react-window's simpler API as a lightweight alternative to TanStack Virtual for virtualizing lists.
What is react-window?
Before TanStack Virtual became the modern standard, react-window (by Brian Vaughn) was the go-to library for list virtualization. It's still widely used in production codebases and offers a more opinionated, component-based API. While labeled "legacy" here because newer solutions exist, it remains a solid choice for simpler virtualization needs.
The Two Core Components
react-window provides two main components:
FixedSizeList
For lists where every item has the same height. You specify height (viewport), itemCount, itemSize (each row's height), and width:
import { FixedSizeList } from 'react-window';
<FixedSizeList
height={400}
itemCount={10000}
itemSize={50}
width="100%"
>
{({ index, style }) => (
<div style={style}>
Row {index}
</div>
)}
</FixedSizeList>
The render prop receives index and style (positioning CSS) for each visible item.
VariableSizeList
For lists with different item heights. You provide an itemSize function instead of a number:
<VariableSizeList
height={400}
itemCount={items.length}
itemSize={(index) => items[index].height}
width="100%"
>
{({ index, style }) => (
<div style={style}>{items[index].content}</div>
)}
</VariableSizeList>
The Trade-Off
react-window is simpler and smaller (~3KB) than TanStack Virtual, but less flexible. It's component-based rather than hook-based, making it easier for beginners but harder to customize deeply.
Key Takeaway: react-window's FixedSizeList and VariableSizeList provide a straightforward, battle-tested approach to virtualization—perfect for projects that need proven simplicity over maximum flexibility.