React Virtual List

3.19.2 · active · verified Sun Apr 19

rc-virtual-list is a React component designed for efficiently rendering large lists by only rendering items visible within the viewport, significantly improving performance and memory usage compared to rendering all items simultaneously. It supports animations and is compatible with older browsers like IE11+. The package, currently at stable version `3.19.2`, receives regular patch updates, indicating an active maintenance schedule. It is part of the `react-component` ecosystem, known for providing foundational UI components often utilized within Ant Design. Its key differentiators include built-in animation support, broad browser compatibility, and a focus on core virtualization logic without opinionated styling, making it highly adaptable to various design systems. It enables smooth scrolling and interaction even with thousands of data entries by precisely managing what's rendered to the DOM.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart renders a virtualized list with 1000 items, demonstrating basic setup and usage of `rc-virtual-list`.

import React, { useState, useEffect } from 'react';
import List from 'rc-virtual-list';

interface Item {
  id: number;
  value: string;
}

const VirtualizedListExample: React.FC = () => {
  const [data, setData] = useState<Item[]>([]);

  useEffect(() => {
    // Generate some mock data for the virtual list
    const generateData = (count: number): Item[] =>
      Array.from({ length: count }).map((_, i) => ({
        id: i,
        value: `Virtual Item ${i + 1}`,
      }));
    setData(generateData(1000)); // Create a list with 1000 items
  }, []);

  return (
    <div style={{ padding: 20, maxWidth: 400, border: '1px solid #ccc' }}>
      <h3>rc-virtual-list Basic Usage</h3>
      <p>This example demonstrates a virtualized list rendering 1000 items.</p>
      <div style={{ height: 300, overflow: 'auto', border: '1px solid #eee' }}>
        <List
          data={data}
          height={300} // The fixed height of the scrollable area
          itemHeight={30} // The estimated height of a single list item
          itemKey="id" // Unique key property for each item
        >
          {(item: Item) => (
            <div
              key={item.id} // Essential for React to correctly manage list elements
              style={{
                padding: '8px 16px',
                borderBottom: '1px solid #f0f0f0',
                lineHeight: '1.5'
              }}
            >
              {item.value}
            </div>
          )}
        </List>
      </div>
    </div>
  );
};

export default VirtualizedListExample;

view raw JSON →