FlatList

FlatList renders large lists efficiently — it only renders items currently visible on screen (lazy loading).

Basic Usage

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

const DATA = [
  { id: '1', title: 'JavaScript' },
  { id: '2', title: 'React Native' },
  { id: '3', title: 'TypeScript' },
]

const CourseList = () => (
  <FlatList
    data={DATA}
    keyExtractor={item => item.id}
    renderItem={({ item }) => (
      <View style={{ padding: 16, borderBottomWidth: 1 }}>
        <Text>{item.title}</Text>
      </View>
    )}
  />
)

FlatList vs ScrollView

FlatListScrollView
RenderingLazy (only visible items)All items at once
PerformanceExcellent for large listsPoor for long lists
Use whenDynamic data, many itemsShort, fixed content

Useful Props

<FlatList
  data={items}
  keyExtractor={item => item.id}
  renderItem={({ item, index }) => <Item data={item} />}
  ItemSeparatorComponent={() => <View style={styles.sep} />}
  ListHeaderComponent={<Header />}
  ListFooterComponent={<Footer />}
  ListEmptyComponent={<Text>No items</Text>}
  onRefresh={handleRefresh}
  refreshing={isLoading}
  onEndReached={loadMore}
  horizontal={false}
/>