ScrollView and FlatList
On the web, a long page scrolls by itself. On a phone, nothing scrolls unless you ask. Sprout's settings screen is short and fixed; its plant list might hold five plants or five hundred. React Native has two main answers, and picking the wrong one makes a big list slow.
The rule
ScrollView renders everything; FlatList renders only what is near the screen.
ScrollView is a scrollable View. Every child is created at once, even the ones far off screen:
<ScrollView contentContainerStyle={{ padding: 16 }}>
<Text>Settings</Text>
<Text>Units</Text>
<Text>About Sprout</Text>
</ScrollView>That is fine for a short, known amount of content. Styles that shape the inner content, such as padding, go in contentContainerStyle. Add horizontal to scroll sideways.
FlatList is for data lists. It virtualizes: it creates rows only for items on or near the screen, and recycles memory as you scroll.
<FlatList
data={plants}
keyExtractor={(plant) => plant.id}
renderItem={({ item }) => <PlantCard plant={item} />}
ItemSeparatorComponent={() => <View style={{ height: 8 }} />}
ListEmptyComponent={<Text>No plants yet. Add one!</Text>}
/>datais the array.renderItemreceives an object; the current element is itsitemfield (plusindex).keyExtractorreturns a unique string for each item so React can track rows.ListEmptyComponent,ListHeaderComponentandListFooterComponentfill the obvious gaps.onEndReachedfires near the bottom, for loading more.
FlatList can also scroll sideways with horizontal, or show a grid with numColumns={2}, which suits a wall of plant photos.
Do not put a FlatList inside a ScrollView that scrolls the same way. The outer one forces every row to render, which defeats virtualization, and React Native warns about it. Use the list's header and footer props instead.