Thuta Learning
React Native
IntermediateMobile DevelopmentIntermediate

Lists with FlatList

React NativeLesson 1020 min

What you'll walk away with

  • Explain the React and native-platform behavior of Lists with FlatList
  • Test accessibility, failure, and lifecycle cases
  • Write maintainable, testable, and performant React Native

Explain it simply

Lists with FlatList, in plain language

FlatList mainly works with three props: data (the array), renderItem (how to display each item), and keyExtractor (a unique key for each item). ScrollView + .map() renders every item upfront, including ones not yet visible on screen, which can cause memory/performance problems with hundreds of items — FlatList instead uses virtualization (rendering only items near the screen and recycling the rest), keeping performance solid for lists with hundreds of items.

Problem → Why → Solution

The problem — why this concept matters

Skipping keyExtractor and relying on the array index as the default key — this can cause bugs when the list changes

A common mistake

Continuing to use ScrollView + .map() for lists with hundreds of items (hurts performance)

Core concept — understand how it works

Treat Lists with FlatList as a native UI contract covering Yoga constraints, pixel density, font scaling, safe areas, the keyboard, touch targets, the accessibility tree, and iOS/Android differences—not merely screen styling syntax.

Mental model
  1. JavaScript state
  2. native component and layout
  3. Android or iOS UI

Explain the React and native-platform behavior of Lists with FlatList

Core syntax or pattern

javascript
import { FlatList, View, Text, StyleSheet } from 'react-native';

const products = [
  { id: '1', name: 'T-Shirt', price: '15000 MMK' },
  { id: '2', name: 'Sneakers', price: '85000 MMK' },
  { id: '3', name: 'Backpack', price: '45000 MMK' },
];

export default function ProductList() {
  return (
    <FlatList
      data={products}
      keyExtractor={(item) => item.id}
      renderItem={({ item }) => (
        <View style={styles.card}>
          <Text style={styles.name}>{item.name}</Text>
          <Text>{item.price}</Text>
        </View>
      )}
    />
  );
}

const styles = StyleSheet.create({
  card: { padding: 16, borderBottomWidth: 1, borderColor: '#eee' },
  name: { fontWeight: '600', fontSize: 16 },
});

Treat Lists with FlatList as a native UI contract covering Yoga constraints, pixel density, font scaling, safe areas, the keyboard, touch targets, the accessibility tree, and iOS/Android differences—not merely screen styling syntax.

Read the code step by step

  1. JavaScript stateimport { FlatList, View, Text, StyleSheet } from 'rea...

    FlatList mainly works with three props: data (the array), renderItem (how to display each item), and keyExtractor (a unique key for each item). ScrollView + .map() renders every item upfront, including ones not yet visible on screen, which can cause memory/performance problems with hundreds of items — FlatList instead uses virtualization (rendering only items near the screen and recycling the rest), keeping performance solid for lists with hundreds of items.

  2. native component and layout<View style={styles.card}>

    Treat Lists with FlatList as a native UI contract covering Yoga constraints, pixel density, font scaling, safe areas, the keyboard, touch targets, the accessibility tree, and iOS/Android differences—not merely screen styling syntax.

  3. Android or iOS UI});

    Test an original Lists with FlatList example on Android and iOS with small and large screens, font scaling, dark mode, keyboard and screen reader use, slow/offline networking, denied permissions, and background/foreground transitions. Use DevTools, tests, and a release build where relevant.

Execution flow
  1. JavaScript state
  2. native component and layout
  3. Android or iOS UI

Success

Explain the React and native-platform behavior of Lists with FlatList

Failure

Skipping keyExtractor and relying on the array index as the default key — this can cause bugs when the list changes

Let's think about this for a moment

FlatList mainly works with three props: data (the array), renderItem (how to display each item), and keyExtractor (a unique key for each item). ScrollView + .map() renders every item upfront, including ones not yet visible on screen, which can cause memory/performance problems with hundreds of items — FlatList instead uses virtualization (rendering only items near the screen and recycling the rest), keeping performance solid for lists with hundreds of items.

Let's connect this to a real scenario

Chat app message lists, e-commerce product lists, social media feeds — FlatList is the standard choice for any list with lots of items like these. Inside renderItem you return a card component for each item, and for keyExtractor you pass item._id or item.id converted to a string — an incorrect key can hurt React's reconciliation performance.

Code Example

javascript
import { FlatList, View, Text, StyleSheet } from 'react-native';

const products = [
  { id: '1', name: 'T-Shirt', price: '15000 MMK' },
  { id: '2', name: 'Sneakers', price: '85000 MMK' },
  { id: '3', name: 'Backpack', price: '45000 MMK' },
];

export default function ProductList() {
  return (
    <FlatList
      data={products}
      keyExtractor={(item) => item.id}
      renderItem={({ item }) => (
        <View style={styles.card}>
          <Text style={styles.name}>{item.name}</Text>
          <Text>{item.price}</Text>
        </View>
      )}
    />
  );
}

const styles = StyleSheet.create({
  card: { padding: 16, borderBottomWidth: 1, borderColor: '#eee' },
  name: { fontWeight: '600', fontSize: 16 },
});
You should see
You'll be able to render a scrollable product list with FlatList.

5-Minute Try-It

Create your own data array (e.g. a list of favorite movies) and try rendering it with FlatList.

A Quick Heads-Up

Don't nest FlatList inside a ScrollView (you'll get a 'VirtualizedList nested inside ScrollView' warning) — use a View for the outer container, ScrollView isn't needed.

Real-world usage

How to apply it in a real project

Test an original Lists with FlatList example on Android and iOS with small and large screens, font scaling, dark mode, keyboard and screen reader use, slow/offline networking, denied permissions, and background/foreground transitions. Use DevTools, tests, and a release build where relevant.

Mini challenge

Build it yourself

Test an original Lists with FlatList example on Android and iOS with small and large screens, font scaling, dark mode, keyboard and screen reader use, slow/offline networking, denied permissions, and background/foreground transitions. Use DevTools, tests, and a release build where relevant.

  • Rebuild the example without copying it
  • Test a normal input and an edge case
  • Predict the compiler or output result before running it
javascript
import { FlatList, View, Text, StyleSheet } from 'react-native';

const products = [
  { id: '1', name: 'T-Shirt', price: '15000 MMK' },
  { id: '2', name: 'Sneakers', price: '85000 MMK' },
  { id: '3', name: 'Backpack', price: '45000 MMK' },
];

export default function ProductList() {
  return (
    <FlatList
      data={products}
      keyExtractor={(item) => item.id}
      renderItem={({ item }) => (
        <View style={styles.card}>
          <Text style={styles.name}>{item.name}</Text>
          <Text>{item.price}</Text>
        </View>
      )}
    />
  );
}

const styles = StyleSheet.create({
  card: { padding: 16, borderBottomWidth: 1, borderColor: '#eee' },
  name: { fontWeight: '600', fontSize: 16 },
});

Expected: Explain the React and native-platform behavior of Lists with FlatList

Show hint

Test an original Lists with FlatList example on Android and iOS with small and large screens, font scaling, dark mode, keyboard and screen reader use, slow/offline networking, denied permissions, and background/foreground transitions. Use DevTools, tests, and a release build where relevant.

Quick quiz 1 / 3

What best describes the core idea of Lists with FlatList?

Quick quiz 2 / 3

Which mistake should you avoid first?

Quick quiz 3 / 3

How should this be applied in a real project?

What to remember

  • JavaScript state → native component and layout → Android or iOS UI
  • Treat Lists with FlatList as a native UI contract covering Yoga constraints, pixel density, font scaling, safe areas, the keyboard, touch targets, the accessibility tree, and iOS/Android differences—not merely screen styling syntax.
  • Skipping keyExtractor and relying on the array index as the default key — this can cause bugs when the list changes
  • Test an original Lists with FlatList example on Android and iOS with small and large screens, font scaling, dark mode, keyboard and screen reader use, slow/offline networking, denied permissions, and background/foreground transitions. Use DevTools, tests, and a release build where relevant.

React Native Documentation — React Native

Easy traps

  • Skipping keyExtractor and relying on the array index as the default key — this can cause bugs when the list changes
  • Continuing to use ScrollView + .map() for lists with hundreds of items (hurts performance)
  • Assuming one simulator's happy path proves every real-device, release-build, permission, accessibility, offline, and lifecycle path.

Hands-on Exercise

Test an original Lists with FlatList example on Android and iOS with small and large screens, font scaling, dark mode, keyboard and screen reader use, slow/offline networking, denied permissions, and background/foreground transitions. Use DevTools, tests, and a release build where relevant.

You'll know it worked when: You'll be able to render a scrollable product list with FlatList.

Updated on

Progress is saved only in this browser on this device. It isn't synced to other devices.

Report a problem with this lessonOpens your email app with this lesson's address filled in — nothing is sent until you send it.

Lists with FlatList | Thuta Learning