React Virtual (version 2.10.4) is a JavaScript library providing a single headless hook (`useVirtual`) for efficiently virtualizing scrollable elements in React applications. It enables the rendering of massive lists, grids, and tables by only mounting the visible items in the DOM, drastically improving performance and memory usage for large datasets. This version, last updated over three years ago, was the predecessor to the more actively maintained and feature-rich `@tanstack/react-virtual` (version 3.x.x), part of the broader TanStack ecosystem. While still functional, it is no longer actively developed or recommended for new projects, with development having shifted entirely to the TanStack-branded successor.
npm install react-virtualVerified import paths — ran on the pinned version, not inferred.
This example demonstrates basic row virtualization with fixed item heights, showing how to set up the scroll container and render only the visible rows using the `useVirtual` hook.
Migrate to `@tanstack/react-virtual`. This involves changing import paths (`from 'react-virtual'` to `from '@tanstack/react-virtual'`), updating hook names (`useVirtual` to `useVirtualizer`), and adapting to new configuration options. No official migration guide from v2 to v3 exists, requiring manual refactoring.
Upgrade to `@tanstack/react-virtual` (v3.x), which is designed for modern React versions. If remaining on `react-virtual` v2, you must use React 16 or 17.
Ensure each `virtualItem` rendered has a stable and unique `key` prop. Typically, `virtualRow.index` or `virtualColumn.index` is used, but for dynamic lists where item identity matters more than position, use a unique ID from your data source if available.
Provide the most accurate possible average `estimateSize` for your items. For truly dynamic sizes, you might need a measurement strategy (though `react-virtual` v2's support for this is less refined than v3's). Consider using libraries that offer automatic size measurement if your item sizes vary significantly.
Downgrade your React version to 16 or 17, or preferably, upgrade your virtualization library to `@tanstack/react-virtual` which supports React 18+.
Ensure the `parentRef` is correctly assigned to the `div` element that serves as the scrollable container. Also, ensure that any logic dependent on `parentRef.current` is conditionally executed only after `parentRef.current` is available.