Skip to the page

Lists: thousands of rows without jank · core

How FlatList virtualization works

FlatList (built on VirtualizedList) renders only the rows inside a window around the screen, measured in screen heights, and replaces far-away rows with empty space, so keys, row cost and window settings decide whether a long list stays smooth.

The notes

What you must know

  • FlatList, SectionList and VirtualizedList keep a render window. windowSize defaults to 21: 10 screens above, the visible screen, and 10 screens below.
  • Rows outside the window are unmounted and replaced by spacer views. Their local state is lost.
  • New rows are rendered in batches on the JS thread (maxToRenderPerBatch 10, every updateCellsBatchingPeriod 50 ms). If the user scrolls faster than rows render, they see blank areas.
  • keyExtractor must return a stable unique id. Index keys break when items are inserted, removed or reordered: state and animations attach to the wrong row.
  • initialNumToRender (default 10) should just fill the first screen. Those first items stay mounted (for fast scroll-to-top).
  • Never put a vertical FlatList inside a vertical ScrollView: the outer ScrollView measures the full height, so virtualization stops. Use ListHeaderComponent and ListFooterComponent.
  • SectionList adds section headers (sticky by default on iOS) on top of the same virtualization.

The red pen

Common traps: mistake → fix

  • Mistake: "FlatList recycles views"

    Fix: FlatList unmounts and mounts rows; FlashList recycles.

  • Mistake: "Index as key is fine"

    Fix: wrong as soon as items are removed, inserted or reordered.

  • Mistake: "Wrap FlatList in a ScrollView to add a header"

    Fix: use ListHeaderComponent.

Easy to hard

Questions interviewers ask, easy to hard

  1. How does FlatList decide which rows to render?
  2. Why is an index key a bug? Show a case.
  3. What does windowSize 21 mean? What happens at 3? At 100?
  4. Why is a FlatList inside a ScrollView a problem?
  5. Why do you see blank areas when you scroll fast?

Practise

Practise with these questions

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview