gpt4 book ai didi

react-native - 基本 FlatList 代码抛出警告 - React Native

转载 作者:行者123 更新时间:2023-12-03 04:39:10 25 4
gpt4 key购买 nike

FlatList 似乎不起作用。我收到此警告。

VirtualizedList:缺少项目的键,请确保在每个项目上指定键属性或提供自定义 keyExtractor。

代码:

<FlatList 
data={[{name: 'a'}, {name: 'b'}]}
renderItem={
(item) => <Text key={Math.random().toString()}>{item.name}</Text>
}
key={Math.random().toString()} />

最佳答案

只需这样做:

<FlatList 
data={[{name: 'a'}, {name: 'b'}]}
renderItem={
({item}) => <Text>{item.name}</Text>
}
keyExtractor={(item, index) => index.toString()}
/>

来源:here

关于react-native - 基本 FlatList 代码抛出警告 - React Native,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44545148/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com