我定义了一个关键道具。仍然反应本地人抛出此警告:
数组或迭代器中的每个子代都应具有唯一的键道具
<MapView
style={styles.map}
>
{
locations.map((location)=> {
if (renderArray[wertwert]){
let content;
if (location.isARealTimeGPS) {
content = <View style={styles.marker}/>
} else {
content = <LocationInfoComponent location={location} handleLocationClick={this.handleLocationClick}
locations={locations} infoVisible={infoVisible}
/>
}
wertwert = wertwert+1;
return (
<MapView.Marker
key={JSON.stringify(location.latitude)}
coordinate={location}
>
{content}
</MapView.Marker>
)
} else {
wertwert = wertwert+1;
}
})
}
</MapView>
最佳答案
我建议您只使用简单的map-index而不是其他任何东西:
<MapView>
{
locations.map((location, index)=> {
...
return (
<MapView.Marker
key={index}
coordinate={location}
>
{content}
</MapView.Marker>
)
})
}
</MapView>