基本 FlatList 代码抛出警告 - React Native [英] Basic FlatList code throws Warning - React Native
本文介绍了基本 FlatList 代码抛出警告 - React Native的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
FlatList 似乎不起作用.我收到此警告.
FlatList does not seem to be working. I get this warning.
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()}
/>
来源:此处
这篇关于基本 FlatList 代码抛出警告 - React Native的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文