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

前端之家收集整理的这篇文章主要介绍了react-native – 基本FlatList代码抛出警告 – React Native前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
FlatList似乎不起作用.我收到了这个警告. @H_403_1@VirtualizedList:缺少项目的键,确保在每个项目上指定键属性或提供自定义keyExtractor.

@H_403_1@码:

<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}
/>
@H_403_1@资料来源:here

原文链接:https://www.f2er.com/react/301263.html

猜你在找的React相关文章