I see the component in react dev tools and each of the Summaries has a unique key on it. But the warning won’t go away.
const summaryData = [
{
id: 1,
box: "one",
sprite: "html5",
},
{
id: 2,
box: "two",
sprite: "envelope",
},
{
id: 3,
box: "three",
sprite: "wordpress",
},
{
id: 4,
box: "four",
sprite: "tongue",
},
];
{summaryData.map((summary) => (
<Summaries
key={`box${summary.id}`}
box={summary.box}
sprite={summary.sprite}
/>
))}
3
Answers
So I figured out that it really wasn't a key problem but a problem with how I did my data in my array. Thanks Konrad.
The problem now is I need to pass html with props and render in Summaries.
If I leave it as is then the html renders but I get the key warning. If I wrap the html inside quotes then it won't render correctly and I see code in Summaries.
You could always create a composite key by concatenating multiple field values or hashing the object.
Try adding the unique key with the index value as below instead. I always find this approach easier to read and you are far less likely to run into any errors also.