DEV Community

Max Angelo Perin (ᜋᜃᜐ)
Max Angelo Perin (ᜋᜃᜐ)

Posted on

Answer: Two children with the same key in React [duplicate]

You can pass another parameter within your map function like so:

this.state.elements.map((element, index) => {
   return <span style={element.myStyle} key={index} >{element}</span>;
});

The second parameter of the Array.prototype.map function actually contains the current index of the particular element in that array.

This way, you'll be sure that your key is not…

Discussion (0)