FlatList helps show a list of items on the screen in a smooth and fast way. It makes scrolling easy and efficient.
FlatList basics (data, renderItem, keyExtractor) in React Native
import { FlatList, Text, View } from 'react-native'; <FlatList data={arrayOfItems} renderItem={({ item }) => <Text>{item.name}</Text>} keyExtractor={item => item.id} />
data is the list of items you want to show.
renderItem tells how to show each item.
keyExtractor gives a unique key for each item to help React Native manage the list efficiently.
const fruits = [{ id: '1', name: 'Apple' }, { id: '2', name: 'Banana' }];
<FlatList
data={fruits}
renderItem={({ item }) => <Text>{item.name}</Text>}
keyExtractor={item => item.id}
/>const emptyList = [];
<FlatList
data={emptyList}
renderItem={({ item }) => <Text>{item.name}</Text>}
keyExtractor={item => item.id}
/>const singleItem = [{ id: '100', name: 'Only One' }];
<FlatList
data={singleItem}
renderItem={({ item }) => <Text>{item.name}</Text>}
keyExtractor={item => item.id}
/>This app shows a list of animal names using FlatList. Each animal has a unique id used as the key. The list is scrollable if needed.
import React from 'react'; import { FlatList, Text, View, SafeAreaView } from 'react-native'; export default function App() { const animals = [ { id: 'a1', name: 'Dog' }, { id: 'a2', name: 'Cat' }, { id: 'a3', name: 'Elephant' } ]; return ( <SafeAreaView style={{ flex: 1, marginTop: 50 }}> <FlatList data={animals} renderItem={({ item }) => <Text style={{ fontSize: 24, padding: 10 }}>{item.name}</Text>} keyExtractor={item => item.id} /> </SafeAreaView> ); }
FlatList only renders items visible on the screen for better performance.
Always provide a unique keyExtractor to avoid warnings and improve list updates.
Common mistake: forgetting keyExtractor or using non-unique keys causes rendering issues.
FlatList shows lists efficiently by rendering only visible items.
Use data to give the list items, renderItem to show each item, and keyExtractor to give unique keys.
This helps your app run smoothly and look good when showing lists.