A FlatList with thousands of rows stays usable because it never mounts all of them. It keeps a band of rows mounted around what the user sees and stands in for most of the rest with empty space of the right size. How wide that band is decides whether a fast fling shows blank space, how much memory the list holds, and whether a row forgets what the user did to it.

Key terms

  • VirtualizedList: the component behind FlatList, which inherits its props, so the window props in this section are VirtualizedList props passed through FlatList.
  • Viewport: the visible area of the list content that is rendered to pixels.
  • Render window: the area in which items are mounted, generally much larger than the viewport.
  • Blank areas: parts of the list that show as empty space because the list could not render the items there fast enough.
  • windowSize: the prop that sets how far the render window reaches beyond the visible area, in units of visible lengths.

Rows outside the window are placeholders

Virtualization keeps a finite render window of active items and replaces every item outside it with blank space of the matching size. Rows outside the window are unmounted, and spacers of that size stand in for them. Without getItemLayout, the spacer after the last rendered row only reaches the furthest row measured so far, so the list does not reserve space for rows it has never measured. The exception is the first initialNumToRender rows (10 by default), which stay mounted to make scroll-to-top feel fast, unless you set initialScrollIndex.

The window follows the scroll. Items close to the visible area render at high priority, and items far from it render incrementally at low priority. Internally, the window starts from the visible area and adds overscan regions ahead of it and behind it, and the total overscan area is capped, which also caps memory consumption.

When scrolling outruns the fill rate

Offscreen content is rendered asynchronously, which keeps memory bounded and scrolling smooth. The price is that a user can scroll faster than the fill rate and momentarily see blank content. When that happens, the user reaches a part of the list where the placeholders have not been replaced by rendered items yet.

A blank area comes from the gap between how fast the user moves through the list and how fast the list renders rows ahead of them. You can give the list more of a head start with a wider window, or make each row cheaper so the list renders it faster. Heavier rows render slower, which is why row cost matters as much as window size.

Choosing a windowSize

windowSize is measured in visible lengths, where 1 is the height of the viewport for a vertical list. The default is 21: the visible screen plus up to 10 screens above it and 10 below. The overscan beyond the visible area is windowSize - 1 visible lengths, split between the two sides, so windowSize={11} keeps the visible screen plus up to 5 screens on each side.

Changing it trades memory against blank space:

  • A bigger windowSize lowers the chance of seeing blank space while scrolling, and costs more memory.
  • A smaller windowSize mounts fewer items at once, which saves memory and may improve performance, but fast scrolling is more likely to reveal momentary blank areas.

Memory consumption here means how much information about the list the app keeps in memory, and too much of it can lead to a crash. A reasonable approach is to lower windowSize when rows are heavy and memory is what hurts, and to leave the default (or raise it) when users fling through long feeds and blank space is the complaint.

Row state does not survive the window

Virtualization fully unmounts the React instances outside the render window, apart from those first initialNumToRender rows. Any other row that leaves the window loses its internal state, and when the user scrolls back, a fresh instance mounts with initial state. A row that tracks "expanded" with its own useState comes back collapsed.

Keep anything the user changes in the item data or in a store outside the rows, such as Redux or Relay, or in the state of the component that renders the list. The comment thread example keeps expanded ids in the parent: expandedIds lives next to the FlatList, and the row reads expandedIds.has(item.id). Because renderItem reads expandedIds, which is not part of data, the list also gets extraData={expandedIds}, the marker prop that tells the list to re-render when rows depend on something outside data. toggle builds a new Set on every press instead of changing the old one, because extraData should be treated immutably.

The example also sets windowSize={11}. Collapsed comments are cheap, but an expanded thread can hold long bodies, and halving the reach of the window keeps fewer of them mounted at once.

The deprecated disableVirtualization prop turns all of this off. It exists for debugging, so don't reach for it to keep row state.

Code Examples

tsx
import {useState} from 'react';
import {FlatList, Pressable, Text} from 'react-native';

type Comment = {id: string; author: string; body: string};

export function CommentThread({comments}: {comments: Comment[]}) {
  // Most rows unmount outside the render window, so expanded ids live here
  const [expandedIds, setExpandedIds] = useState<ReadonlySet<string>>(
    () => new Set(),
  );

  const toggle = (id: string) =>
    setExpandedIds(prev => {
      const next = new Set(prev);
      if (next.has(id)) {
        next.delete(id);
      } else {
        next.add(id);
      }
      return next;
    });

  return (
    <FlatList
      data={comments}
      keyExtractor={item => item.id}
      extraData={expandedIds}
      windowSize={11}
      renderItem={({item}) => (
        <Pressable onPress={() => toggle(item.id)}>
          <Text>{item.author}</Text>
          {expandedIds.has(item.id) && <Text>{item.body}</Text>}
        </Pressable>
      )}
    />
  );
}
✓ Completed