我最近开始使用react-native
,并且遇到了FlatList
组件.当使用react
时,我总是将map
与数组一起使用.
我用的是FlatList
,但当我想更改FlatList
中的flex-direction
项时出现了问题,所以我恢复使用map
.
以下是使用这两种方法的两个示例:
map
{
this.state.images.map(image => {
return (
<UsersImage key={ image } source={{ uri: image }} />
)
})
}
FlatList
<FlatList
data={ this.state.images }
renderItem={({item}) => {
return (
<UsersImage source={{ uri: item }} />
)
}}
keyExtractor={(item, index) => index}
/>
有人能解释为什么一个人应该用FlatList
比map
,或者反之亦然吗?