What is the purpose of the data prop in a FlatList?
The data prop provides the array of items that the FlatList will display. Each item in this array will be rendered as a list element.
Click to reveal answer
beginner
Explain the role of the renderItem prop in FlatList.
The renderItem prop is a function that tells FlatList how to display each item. It receives an object with the item data and returns a React element to render.
Click to reveal answer
beginner
Why do we use keyExtractor in FlatList?
The keyExtractor prop provides a unique key for each item in the list. This helps React Native track items efficiently and avoid rendering issues.
Click to reveal answer
intermediate
What happens if you don't provide a keyExtractor in FlatList?
If keyExtractor is missing, FlatList tries to use the item index as the key, which can cause problems when items are added, removed, or reordered, leading to UI glitches.
Click to reveal answer
intermediate
How does FlatList improve performance compared to ScrollView for long lists?
FlatList only renders items that are visible on the screen plus a small buffer, reducing memory use and improving performance. ScrollView renders all items at once, which can be slow for long lists.
Click to reveal answer
What type of data does the data prop in FlatList expect?
AA number
BA single object
CA string
DAn array of items
✗ Incorrect
FlatList expects an array of items to render each as a list element.
Which prop defines how each item in FlatList is displayed?
AkeyExtractor
Bdata
CrenderItem
Dstyle
✗ Incorrect
renderItem is the function that returns the UI for each list item.
What does the keyExtractor function return?
AA unique string key for each item
BThe item data itself
CThe index number as a number
DThe entire data array
✗ Incorrect
keyExtractor returns a unique string key to help React identify each item.
If you omit keyExtractor, what key does FlatList use by default?
ANo key
BItem index
CItem name
DItem id
✗ Incorrect
FlatList uses the item index as the key if keyExtractor is not provided.
Why is FlatList preferred over ScrollView for long lists?
AFlatList renders only visible items, improving performance
BFlatList supports animations better
CScrollView does not support scrolling
DFlatList uses less memory for images
✗ Incorrect
FlatList renders only visible items plus a buffer, making it faster and less memory-heavy for long lists.
Describe how you would use data, renderItem, and keyExtractor together in a FlatList.
Think of data as your list of friends, renderItem as how you show each friend, and keyExtractor as giving each friend a name tag.
You got /3 concepts.
Explain why providing a unique key with keyExtractor is important in FlatList.
Imagine trying to find a friend in a crowd without name tags — it gets confusing!
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of the keyExtractor prop in a React Native FlatList?
easy
A. To handle user taps on list items.
B. To define how each item should be displayed on the screen.
C. To specify the data source for the list.
D. To provide a unique key for each list item to help React identify items.
Solution
Step 1: Understand the role of keyExtractor
The keyExtractor is used to give each item a unique key, which helps React track which items changed, added, or removed.
Step 2: Differentiate from other props
renderItem defines how to show items, data is 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 D
Quick Check:
keyExtractor = unique keys [OK]
Hint: Keys uniquely identify items in lists [OK]
Common Mistakes:
Confusing keyExtractor with renderItem
Using index as key without keyExtractor
Thinking keyExtractor handles item display
2. Which of the following is the correct syntax to define a FlatList with data and renderItem props?
easy
A. {item}} />
B. {item}} />
C. {item}} />
D. {data}} />
Solution
Step 1: Check prop names
The correct props are data for the list and renderItem for rendering each item.
Step 2: Check renderItem function parameter
renderItem receives an object with item property, so it should be ({item}) => ....
Final Answer:
<FlatList data={items} renderItem={({item}) => <Text>{item}</Text>} /> -> Option A
Quick Check:
Correct props and destructuring = C [OK]
Hint: Use data and renderItem with ({item}) parameter [OK]
Common Mistakes:
Using wrong prop names like 'items' or 'render'
Not destructuring item in renderItem
Passing item directly without braces
3. Given this code snippet, what will be displayed on the screen?
B. renderItem should not use destructuring for item.
C. Missing keyExtractor prop, which may cause warnings or errors.
D. data should be an array of strings, not objects.
Solution
Step 1: Check for keyExtractor
The code does not provide a keyExtractor, so React Native will warn because keys are needed for list items.
Step 2: Validate other props
renderItem correctly destructures item, data can be objects, and style is optional.
Final Answer:
Missing keyExtractor prop, which may cause warnings or errors. -> Option C
Quick Check:
keyExtractor missing = warning [OK]
Hint: Always add keyExtractor for unique keys [OK]
Common Mistakes:
Ignoring missing keyExtractor warnings
Thinking renderItem destructuring is wrong
Believing style prop is mandatory
5. You want to display a list of users with unique IDs, but your data array has duplicate IDs. How should you modify the keyExtractor to avoid key conflicts in FlatList?