Using FlatList in React Native helps keep your app smooth by rendering only visible items on the screen. This means it can maintain a steady frame rate of 60fps on most devices, avoiding slowdowns caused by rendering large lists all at once. Memory usage stays low because off-screen items are not kept in memory unnecessarily, which also helps save battery life.
FlatList basics (data, renderItem, keyExtractor) in React Native - Build, Publish & Deploy
To keep your FlatList fast and smooth, always provide a keyExtractor that returns a unique key for each item. This helps React Native track items efficiently and avoid unnecessary re-renders. Use simple, lightweight components in renderItem and avoid heavy computations inside it. Also, consider using initialNumToRender and maxToRenderPerBatch props to control how many items load initially and during scrolling.
FlatList is part of React Native core, so it does not add extra size to your app bundle. Using FlatList instead of custom list implementations can reduce your app size by avoiding extra libraries. Startup time is not affected by FlatList itself, but large data sets passed to it can delay initial rendering. To improve startup, load data asynchronously and show placeholders or loading indicators.
FlatList works similarly on both iOS and Android, but there are subtle differences. On iOS, FlatList uses UICollectionView under the hood, while on Android it uses RecyclerView. This means Android may handle very large lists slightly better in some cases. Also, Android requires explicit handling of nested scroll views if FlatList is inside a scrollable parent. Testing on both platforms is important to ensure smooth scrolling and consistent behavior.
Using FlatList aligns with both Apple App Store and Google Play guidelines as it helps create smooth, responsive user interfaces. Ensure your list content respects privacy and content policies. Avoid loading excessive data that may cause crashes or poor user experience, as this can lead to app rejection. Also, make sure your app handles accessibility properly by supporting screen readers and keyboard navigation for list items.
If your FlatList screen takes too long to load, it is likely because you are rendering too many items at once or doing heavy work inside renderItem. Check if you are missing a proper keyExtractor, causing inefficient re-renders. Also, loading large data synchronously can block the UI thread. Try loading data asynchronously and limit initial items rendered with FlatList props.
Practice
keyExtractor prop in a React Native FlatList?Solution
Step 1: Understand the role of
ThekeyExtractorkeyExtractoris used to give each item a unique key, which helps React track which items changed, added, or removed.Step 2: Differentiate from other props
renderItemdefines how to show items,datais the list source, and tap handling is done separately.Final Answer:
To provide a unique key for each list item to help React identify items. -> Option DQuick Check:
keyExtractor = unique keys [OK]
- Confusing keyExtractor with renderItem
- Using index as key without keyExtractor
- Thinking keyExtractor handles item display
FlatList with data and renderItem props?Solution
Step 1: Check prop names
The correct props aredatafor the list andrenderItemfor rendering each item.Step 2: Check renderItem function parameter
renderItemreceives an object withitemproperty, so it should be({item}) => ....Final Answer:
<FlatList data={items} renderItem={({item}) => <Text>{item}</Text>} /> -> Option AQuick Check:
Correct props and destructuring = C [OK]
- Using wrong prop names like 'items' or 'render'
- Not destructuring item in renderItem
- Passing item directly without braces
const data = [{id: '1', name: 'Apple'}, {id: '2', name: 'Banana'}];
<FlatList
data={data}
keyExtractor={item => item.id}
renderItem={({item}) => <Text>{item.name}</Text>}
/>
Solution
Step 1: Analyze data and keyExtractor
Data has two objects with ids and names. keyExtractor returns item.id, which is correct.Step 2: Analyze renderItem output
renderItem showsitem.name, so it will display 'Apple' and 'Banana'.Final Answer:
A list showing 'Apple' and 'Banana' as text items. -> Option BQuick Check:
renderItem shows item.name = Apple, Banana [OK]
- Thinking keyExtractor missing causes blank screen
- Confusing item.id with item.name in renderItem
- Assuming renderItem is missing or wrong
FlatList usage?
const data = [{id: 'a'}, {id: 'b'}];
<FlatList
data={data}
renderItem={({item}) => <Text>{item.id}</Text>}
/>
Solution
Step 1: Check for keyExtractor
The code does not provide akeyExtractor, so React Native will warn because keys are needed for list items.Step 2: Validate other props
renderItem correctly destructuresitem, data can be objects, and style is optional.Final Answer:
Missing keyExtractor prop, which may cause warnings or errors. -> Option CQuick Check:
keyExtractor missing = warning [OK]
- Ignoring missing keyExtractor warnings
- Thinking renderItem destructuring is wrong
- Believing style prop is mandatory
keyExtractor to avoid key conflicts in FlatList?
const users = [
{id: '1', name: 'Alice'},
{id: '1', name: 'Bob'},
{id: '2', name: 'Charlie'}
];
<FlatList
data={users}
keyExtractor={item => item.id}
renderItem={({item}) => <Text>{item.name}</Text>}
/>
Solution
Step 1: Identify duplicate keys problem
Using onlyitem.idcauses duplicate keys for '1', which React warns against.Step 2: Fix keyExtractor to ensure uniqueness
Combiningitem.idwithindexcreates unique keys like '11', '12', '20'.Final Answer:
Change keyExtractor to combine id and index: (item, index) => item.id + index -> Option AQuick Check:
Unique keys prevent warnings = Change keyExtractor to combine id and index:(item, index) => item.id + index[OK]
- Ignoring duplicate keys causing warnings
- Using only index loses stable keys
- Removing keyExtractor causes errors
Ready to prove it?
Pass the test and this pattern moves unknown
