0
0
React Nativemobile~20 mins

FlatList performance optimization in React Native - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
πŸŽ–οΈ
FlatList Performance Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate
2: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}
    />
  );
}
A10 items are rendered initially on screen
BNo items are rendered until user scrolls
COnly 1 item is rendered initially
DAll 100 items are rendered initially
Attempts:
2 left
πŸ’‘ Hint
Look at the initialNumToRender prop value.
❓ lifecycle
intermediate
2:00remaining
Effect of extraData on FlatList re-render
What happens when the extraData prop changes in a FlatList?

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?
AFlatList re-renders the entire list including off-screen items
BFlatList ignores extraData and does not re-render
CFlatList crashes due to extraData prop
DFlatList re-renders all visible items to reflect the new selection
Attempts:
2 left
πŸ’‘ Hint
extraData tells FlatList to re-render when it changes.
πŸ”§ Debug
advanced
2: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
ASetting initialNumToRender to a low number causing slow rendering
BUsing anonymous functions inside renderItem causing re-creation on each render
CUsing keyExtractor with unique keys causing key conflicts
DUsing getItemLayout for fixed item height causing layout errors
Attempts:
2 left
πŸ’‘ Hint
Think about what causes unnecessary re-renders.
🧠 Conceptual
advanced
2:00remaining
Purpose of getItemLayout in FlatList
Why would you use the getItemLayout prop in a FlatList?

Choose the best explanation.
ATo customize the rendering of each item based on its index
BTo dynamically load more items when scrolling near the end
CTo provide fixed height and offset info for each item to improve scroll performance
DTo disable scrolling when the list is empty
Attempts:
2 left
πŸ’‘ Hint
Think about how FlatList calculates scroll positions.
❓ navigation
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:
AUse maintainVisibleContentPosition prop with appropriate minIndex and autoscrollToTop false
BReset scroll position to 0 manually after data update
CUse extraData prop to force re-render
DCall scrollToEnd after updating data
Attempts:
2 left
πŸ’‘ Hint
Think about props designed to keep scroll stable on prepending data.