Vision UI

FlashList

A high-performance list component with virtual scrolling support

FlashList

A high-performance list component that supports virtual scrolling for handling large datasets efficiently while maintaining React Native-like APIs.

Features

  • Virtual Scrolling: Only renders visible items for optimal performance
  • React Native-like API: Familiar interface similar to React Native's FlatList
  • Automatic Fallback: Falls back to standard rendering when virtual scrolling isn't needed
  • Flexible Sizing: Supports both fixed and variable item sizes
  • Scroll Events: Built-in support for scroll events and end-reached detection

Basic Usage

import { FlashList } from "@/components/core/v2/flash-list";

const data = [
  { id: "1", title: "Item 1" },
  { id: "2", title: "Item 2" },
  // ... more items
];

function MyList() {
  return (
    <FlashList
      data={data}
      renderItem={({ item, index }) => (
        <div className="border-b p-4">
          <h3>{item.title}</h3>
        </div>
      )}
      keyExtractor={(item) => item.id}
      height={400}
      estimatedItemSize={60}
    />
  );
}

Props

Core Props

PropTypeDescription
dataT[]Array of items to render
renderItem(info: { item: T; index: number }) => React.ReactNodeFunction to render each item
keyExtractor(item: T, index: number) => stringFunction to extract unique keys

Virtual Scrolling Props

PropTypeDefaultDescription
itemSizenumber | ((index: number) => number)-Size of each item (enables virtual scrolling)
estimatedItemSizenumber50Estimated size for virtual scrolling
heightnumber | string400Height of the list container
widthnumber | string"100%"Width of the list container
overscannumber5Number of items to render outside the viewport

Scroll and Layout Props

PropTypeDefaultDescription
onEndReached() => void-Called when user scrolls near the end
onEndReachedThresholdnumber0.1Distance from end to trigger onEndReached (0-1)
onScroll(e: React.UIEvent<HTMLDivElement>) => void-Scroll event handler
horizontalbooleanfalseEnable horizontal scrolling

Layout Props

PropTypeDescription
ListHeaderComponentReact.ReactNode | (() => React.ReactNode)Component to render at the top
ListFooterComponentReact.ReactNode | (() => React.ReactNode)Component to render at the bottom
classNamestringCSS classes for the container
contentContainerClassNamestringCSS classes for the content container

Virtual Scrolling

The FlashList automatically enables virtual scrolling when you provide an itemSize prop. This dramatically improves performance for large datasets by only rendering items that are currently visible.

Fixed Item Size

<FlashList
  data={largeDataset}
  renderItem={renderItem}
  itemSize={80} // Fixed height of 80px per item
  height={400}
/>

Variable Item Size

<FlashList
  data={largeDataset}
  renderItem={renderItem}
  itemSize={(index) => (index % 2 === 0 ? 60 : 100)} // Variable heights
  height={400}
/>

Performance Tips

  1. Always provide keyExtractor for stable item identification
  2. Use estimatedItemSize that's close to your actual item size
  3. Set appropriate overscan values (higher = smoother scrolling, more DOM nodes)
  4. Avoid complex calculations in renderItem - memoize if needed

Examples

Basic List with Virtual Scrolling

function VirtualListExample() {
  const data = Array.from({ length: 10000 }, (_, i) => ({
    id: `item-${i}`,
    title: `Item ${i}`,
  }));

  return (
    <FlashList
      data={data}
      renderItem={({ item }) => (
        <div className="border-b p-4">
          <h3>{item.title}</h3>
        </div>
      )}
      keyExtractor={(item) => item.id}
      itemSize={60}
      height={400}
      onEndReached={() => console.log("Reached end")}
    />
  );
}
function ListWithHeaderFooter() {
  return (
    <FlashList
      data={data}
      renderItem={renderItem}
      ListHeaderComponent={() => (
        <div className="bg-gray-100 p-4">
          <h2>My List</h2>
        </div>
      )}
      ListFooterComponent={() => (
        <div className="bg-gray-100 p-4">
          <p>End of list</p>
        </div>
      )}
      itemSize={60}
      height={400}
    />
  );
}

Horizontal Scrolling

function HorizontalList() {
  return (
    <FlashList
      data={data}
      renderItem={renderItem}
      horizontal={true}
      itemSize={200}
      width={400}
      height={100}
    />
  );
}
Edit on GitHub

Last updated on