📅  最后修改于: 2023-12-03 15:34:38.565000             🧑  作者: Mango
React Native FlatList is a component that allows you to create a list of items efficiently. It renders only the visible items, which improves performance and reduces memory usage. It is a commonly used component in React Native.
React Native FlatList has several features that make it a powerful tool for displaying large lists. Some of its key features include:
import React from 'react';
import { FlatList, Text, View } from 'react-native';
const data = [
{ key: 'Apple' },
{ key: 'Banana' },
{ key: 'Cherry' },
{ key: 'Durian' },
{ key: 'Elderberry' },
{ key: 'Fig' },
{ key: 'Grape' },
{ key: 'Honeyberry' },
{ key: 'Iced melon' },
{ key: 'Jackfruit' },
{ key: 'Kiwi' },
{ key: 'Lemon' },
{ key: 'Mango' },
{ key: 'Nectarine' },
];
const Item = ({ title }) => (
<View style={{ backgroundColor: '#fff' }}>
<Text style={{ fontSize: 24 }}>{title}</Text>
</View>
);
const FlatListExample = () => {
const renderItem = ({ item }) => (
<Item title={item.key} />
);
return (
<FlatList
data={data}
renderItem={renderItem}
ItemSeparatorComponent={() => <View style={{ height: 1, backgroundColor: '#f2f2f2' }} />}
/>
);
};
export default FlatListExample;
React Native FlatList is a powerful tool for displaying large lists efficiently and with minimal memory usage. It is easy to configure and has several features that make it a versatile component in your React Native application.