React Native interview question · Most asked
When would you use FlatList instead of ScrollView, and how do you make long lists fast?
Summary
Use FlatList (or SectionList) for long or unbounded lists: it virtualises, rendering only items near the screen. ScrollView renders every child at once.
Longer Answer
For speed: stable keyExtractor IDs; memoised row components with stable props; light rows; thumbnails sized for the row; tuning initialNumToRender, windowSize and maxToRenderPerBatch; getItemLayout when rows have a fixed height; and guarding onEndReached so pagination doesn't fire repeatedly. Very large lists can use a recycling list library.
Key Points
- ScrollView renders everything; FlatList virtualises.
- Stable keys, memoised rows, small images.
- Tune window sizes; getItemLayout for fixed heights.
Deep dive: Mobile Apps with React Native and Expo: Lists with FlatList
Explanation
What interviewers look for
Understanding virtualisation and practical optimisation steps beyond 'use FlatList'.
Follow-up questions
- Why not use the index as a key?
- How do you implement infinite scrolling?
More most-asked React Native questions
- What is React Native, and how does it differ from a hybrid (WebView) app?
- Explain the React Native threading model.
- What is the React Native New Architecture?
- Where should you store data on the device, and what should never go in AsyncStorage?
- How would you make a React Native app work offline?
- How do you handle authentication tokens in a mobile app?
- A screen in your React Native app is slow. How do you investigate and fix it?
- What can be shipped with an over-the-air (OTA) update, and what can't?