我共同面临的Warning: Each child in an array or iterator should have a unique "key" prop
错误与我的道具组成部分,尽管设置了关键我阵列的unqiueID为返回的div元素我看到这个警告的关键。我是否将它设置在错误的元素上?它可能与嵌套map
有关吗?ReactJS - 缺少关键尽管在元
JSON实例:
{
annotationId: 117,
title: "Test",
discovery: "Test 123",
annotation_comments: [{
annotationCommentId: 12,
comment: "Lorem Ipsum"
}]
}
详细的错误:
in AnnotationCard (created by AnnotationFeed)
in AnnotationFeed (created by AnnotationFeedContainer)
in div (created by AnnotationFeedContainer)
in AnnotationFeedContainer (created by Annotation)
in div (created by Annotation)
in Annotation
组件:
//Loop through JSON and component
const AnnotationFeed = props => {
return (
<div>
{
props.annotations.map((annotation, index) => {
return (
<AnnotationCard {...annotation}>
{ annotation.annotation_comments.map((comment, i) => <Comments {...comment} />)}
</AnnotationCard>
);
})
}
</div>
)
}
const AnnotationCard = props => {
return (
<div key={props.annotationIdHash}>
<h4>{props.title}</h4>
<p>{props.discovery}</p>
</div>
)
}
const Comments = props => {
return (
<div key={props.annotationCommentId}>
<h4>{props.comment}</h4>
</div>
)
}
你没有设定一个关键道具 – linasmnew