What is the main purpose of FlatList in React Native?
FlatList is designed to efficiently render large lists by only rendering items that are currently visible on the screen, improving performance and memory usage.
Click to reveal answer
beginner
How does FlatList improve performance when handling large datasets?
FlatList uses lazy loading and virtualization, rendering only a small subset of items visible on the screen instead of all items at once.
Click to reveal answer
intermediate
What is virtualization in the context of FlatList?
Virtualization means FlatList creates and keeps in memory only the items currently visible plus a small buffer, reducing memory use and improving scroll performance.
Click to reveal answer
beginner
Why is rendering all items in a large list at once a problem on mobile devices?
Rendering all items uses a lot of memory and CPU, causing slow app performance, laggy scrolling, and possible crashes on devices with limited resources.
Click to reveal answer
intermediate
What role does the 'keyExtractor' prop play in FlatList's efficiency?
The 'keyExtractor' helps FlatList identify items uniquely, enabling efficient updates and re-renders only for changed items, which improves performance.
Click to reveal answer
What technique does FlatList use to handle large datasets efficiently?
AVirtualization and lazy loading
BRendering all items at once
CUsing multiple threads
DCaching all data in memory
✗ Incorrect
FlatList uses virtualization and lazy loading to render only visible items, improving performance.
Why is rendering all list items at once bad for mobile apps?
AIt improves battery life
BIt makes the app look colorful
CIt uses too much memory and slows down scrolling
DIt reduces app size
✗ Incorrect
Rendering all items consumes memory and CPU, causing lag and poor user experience.
What does the 'keyExtractor' prop do in FlatList?
AIdentifies each item uniquely for efficient updates
BLoads images faster
CChanges the background color
DSorts the list alphabetically
✗ Incorrect
'keyExtractor' provides unique keys to help FlatList update only changed items.
FlatList renders items that are:
ARandomly selected items
BOnly visible on the screen plus a small buffer
COnly the first 10 items
DAll items in the dataset
✗ Incorrect
FlatList renders visible items plus a buffer to optimize performance.
Which of these is NOT a benefit of FlatList's virtualization?
AReduced memory usage
BSmoother scrolling
CFaster app startup
DRendering all items simultaneously
✗ Incorrect
FlatList does NOT render all items simultaneously; that would hurt performance.
Explain how FlatList manages to display large lists without slowing down the app.
Think about how it avoids showing everything at once.
You got /4 concepts.
Describe the importance of the 'keyExtractor' prop in FlatList's efficient rendering.
How does FlatList know which items changed?
You got /3 concepts.
Practice
(1/5)
1. Why does FlatList in React Native handle large datasets efficiently?
easy
A. Because it disables scrolling to reduce load
B. Because it loads all items at once in memory
C. Because it uses a database to store items
D. Because it renders only the items visible on the screen
Solution
Step 1: Understand rendering behavior of FlatList
FlatList renders only the items currently visible on the screen, not the entire list at once.
Step 2: Effect on performance
This selective rendering reduces memory use and improves scrolling performance for large datasets.
Final Answer:
Because it renders only the items visible on the screen -> Option D
Quick Check:
Rendering visible items only = A [OK]
Hint: FlatList renders visible items only for smooth performance [OK]
Common Mistakes:
Thinking FlatList loads all data at once
Confusing FlatList with ScrollView
Assuming FlatList disables scrolling
2. Which of the following is the correct way to provide a unique key for each item in a FlatList?
easy
A. keyExtractor={item => item.id.toString()}
B. keyExtractor={item => Math.random()}
C. keyExtractor={item => 'key'}
D. keyExtractor={item => item.name + item.age}
Solution
Step 1: Understand keyExtractor purpose
keyExtractor must return a unique string for each item to help React identify items efficiently.
Step 2: Evaluate options
keyExtractor={item => item.id.toString()} uses a unique id converted to string, which is correct. keyExtractor={item => Math.random()} uses random values causing instability. keyExtractor={item => 'key'} returns the same key for all items, which is wrong. keyExtractor={item => item.name + item.age} may not guarantee uniqueness.
Final Answer:
keyExtractor={item => item.id.toString()} -> Option A
Quick Check:
Unique stable keys = D [OK]
Hint: Use stable unique IDs as keys, not random or constant strings [OK]
Common Mistakes:
Using random values for keys
Using same key for all items
Concatenating fields that may not be unique
3. What will happen if you use FlatList without providing a keyExtractor when rendering a large list?
medium
A. FlatList will use index as key but may cause rendering issues
B. FlatList will automatically generate unique keys correctly
C. FlatList will crash immediately
D. FlatList will render all items at once
Solution
Step 1: Default key behavior without keyExtractor
Without keyExtractor, FlatList uses the item index as the key by default.
Step 2: Consequences of using index as key
Using index can cause rendering issues when items change order or are added/removed, leading to inefficient updates or UI glitches.
Final Answer:
FlatList will use index as key but may cause rendering issues -> Option A
Quick Check:
No keyExtractor = index keys = C [OK]
Hint: No keyExtractor means index keys, which can cause bugs [OK]
Common Mistakes:
Assuming FlatList crashes without keyExtractor
Thinking FlatList auto-generates unique keys
Believing all items render at once
4. You notice your FlatList is lagging when scrolling a large dataset. Which fix will improve performance?
medium
A. Remove the keyExtractor prop
B. Use ScrollView instead of FlatList
C. Implement getItemLayout to optimize item measurement
D. Render all items at once by disabling virtualization
Solution
Step 1: Identify performance issue cause
Lag often happens because FlatList calculates item sizes dynamically, causing extra work during scrolling.
Implement getItemLayout to optimize item measurement -> Option C
Quick Check:
Use getItemLayout for smooth scrolling = A [OK]
Hint: Use getItemLayout to speed up FlatList scrolling [OK]
Common Mistakes:
Removing keyExtractor which worsens performance
Switching to ScrollView which loads all items
Disabling virtualization causing memory issues
5. You want to display a large list of chat messages with FlatList. Some messages have the same id due to server bugs. How should you ensure smooth rendering?
hard
A. Use item.id as keyExtractor ignoring duplicates
B. Concatenate item.id with index in keyExtractor to ensure uniqueness
C. Remove duplicate messages before passing data to FlatList
D. Use ScrollView instead of FlatList
Solution
Step 1: Understand duplicate key problem
Duplicate keys cause React to misidentify items, leading to rendering bugs and poor performance.
Step 2: Create unique keys despite duplicates
Concatenating item.id with index ensures keys are unique even if ids repeat, maintaining FlatList efficiency.
Final Answer:
Concatenate item.id with index in keyExtractor to ensure uniqueness -> Option B
Quick Check:
Unique keys despite duplicates = B [OK]
Hint: Add index to keys if IDs are not unique [OK]
Common Mistakes:
Ignoring duplicate keys causing UI bugs
Removing duplicates which may lose data
Switching to ScrollView losing performance benefits
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.