Challenge - 5 Problems
FlatList Performance Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
β ui_behavior
intermediate2:00remaining
FlatList initial rendering behavior
What will be the visible number of items rendered initially by this FlatList component?
import React from 'react';
import { FlatList, Text } from 'react-native';
const data = Array.from({ length: 100 }, (_, i) => ({ id: i.toString(), value: `Item ${i}` }));
export default function MyList() {
return (
{item.value} }
keyExtractor={item => item.id}
initialNumToRender={10}
/>
);
} React Native
import React from 'react'; import { FlatList, Text } from 'react-native'; const data = Array.from({ length: 100 }, (_, i) => ({ id: i.toString(), value: `Item ${i}` })); export default function MyList() { return ( <FlatList data={data} renderItem={({ item }) => <Text>{item.value}</Text>} keyExtractor={item => item.id} initialNumToRender={10} /> ); }
Attempts:
2 left
π‘ Hint
Look at the initialNumToRender prop value.
β Incorrect
The initialNumToRender prop controls how many items FlatList renders initially. Here it is set to 10, so 10 items appear on screen first.
β lifecycle
intermediate2:00remaining
Effect of extraData on FlatList re-render
What happens when the extraData prop changes in a FlatList?
Consider this snippet:
What is the effect of changing selectedId?
Consider this snippet:
<FlatList
data={items}
extraData={selectedId}
renderItem={({ item }) => <Item selected={item.id === selectedId} />}
keyExtractor={item => item.id}
/>What is the effect of changing selectedId?
Attempts:
2 left
π‘ Hint
extraData tells FlatList to re-render when it changes.
β Incorrect
extraData is used to tell FlatList to re-render when some external data changes. Here, changing selectedId causes visible items to update their selected state.
π§ Debug
advanced2:00remaining
Identifying cause of FlatList lag on scroll
A FlatList scrolls slowly and lags on a device. Which of these is the most likely cause?
Options:
A) Using anonymous functions inside renderItem
B) Setting initialNumToRender to 5
C) Using keyExtractor with unique keys
D) Using getItemLayout for fixed item height
Options:
A) Using anonymous functions inside renderItem
B) Setting initialNumToRender to 5
C) Using keyExtractor with unique keys
D) Using getItemLayout for fixed item height
Attempts:
2 left
π‘ Hint
Think about what causes unnecessary re-renders.
β Incorrect
Anonymous functions inside renderItem cause new function instances on every render, leading to performance issues and lag.
π§ Conceptual
advanced2:00remaining
Purpose of getItemLayout in FlatList
Why would you use the getItemLayout prop in a FlatList?
Choose the best explanation.
Choose the best explanation.
Attempts:
2 left
π‘ Hint
Think about how FlatList calculates scroll positions.
β Incorrect
getItemLayout lets FlatList know the height and offset of items upfront, so it can jump to positions and render efficiently without measuring on the fly.
expert
3:00remaining
Maintaining scroll position after data update
You update the data array of a FlatList by prepending new items at the start. What is the best way to keep the userβs scroll position stable so the visible content does not jump?
Options:
Options:
Attempts:
2 left
π‘ Hint
Think about props designed to keep scroll stable on prepending data.
β Incorrect
maintainVisibleContentPosition helps FlatList keep the visible content stable when new items are added at the start, preventing jumpy scroll.