Answer the question
In order to leave comments, you need to log in
Why does React complain about key if it exists and is unique?
There is a component:
import Comment from "../Comment/Comment";
export default function Comments({ comments }) {
return(
<div className={"comments"}>
{comments.map(element =>
<Comment
forKey={element.id}
name={element.name}
/>
)}
</div>
)
}
export default function Comment({ forKey, name }) {
console.log(forKey)
return(
<div key={forKey} className={"comment"}>
{name}
</div>
)
}
Answer the question
In order to leave comments, you need to log in
The key must be where the array is directly formed, that is, inside the map
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question