Answer the question
In order to leave comments, you need to log in
How to add a key to each list item in React?
Help me figure out how to interact with React keys. I am passing the uuid() key to the function. But this key is the key of the entire list (an array of objects), and I want each object of this array to have such a unique key. The component code is here: https://codepen.io/iliyasold/pen/oNoZKov What am I not understanding here? How to win it?
Right now I am getting this:
Answer the question
In order to leave comments, you need to log in
The key must be natural, for example, the Id of the entity (in your case, a comment) from the database. If it is not there, then do not suffer and use the ordinal number of the element, as you have written.
You can also remove an element (removeCommentItem) by index.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question