In React Native, ScrollView and FlatList are used to display scrollable content. ScrollView is suitable for small content, while FlatList is optimized for large data sets.
data and renderItemSimulate adding items to a scrollable container (like a phone screen).
Current Mode: Vertical ScrollView
// ScrollView example for small static content
import { ScrollView, Text } from "react-native";
export default function App() {
return (
<ScrollView>
<Text>Item 1</Text>
<Text>Item 2</Text>
<Text>Item 3</Text>
</ScrollView>
);
}
// FlatList example for large dynamic lists
import { FlatList, Text } from "react-native";
const data = [
{ id: "1", name: "Apple" },
{ id: "2", name: "Banana" },
{ id: "3", name: "Orange" }
];
export default function App() {
return (
<FlatList
data={data}
keyExtractor={(item) => item.id}
renderItem={({ item }) => <Text>{item.name}</Text>}
/>
);
}
ScrollView shows all items at once and may slow down with large data. FlatList renders only visible items, improving performance significantly.
Imagine ScrollView as a long paper already printed, while FlatList prints only what you can currently see on the screen.
keyExtractorinitialNumToRender for optimization