[英]React app throwing error about key, but I have already assigned a unique key at the top level
The error you are seeing is because the keys you have set are not unique, or undefined.您看到的错误是因为您设置的键不是唯一的或未定义的。
From what you have answered in the comments, you are using some kind of UUID to generate said id
values.根据您在评论中的回答,您正在使用某种 UUID 来生成所述
id
值。 Since you haven't included that code in your question, you should probably verify the following:由于您没有在问题中包含该代码,因此您可能应该验证以下内容:
The UUIDs you are generating are indeed unique, and you are not accidentally reusing them or setting the same UUID for all records.您生成的 UUID 确实是唯一的,您不会意外地重用它们或为所有记录设置相同的 UUID。
The id
field is always populated and React doesn't render the list with the values still undefined
id
字段总是被填充,并且 React 不会呈现值仍然undefined
的列表
To check both those suggestions, and any further investigations you may need, you have a variety of tools available.要检查这些建议以及您可能需要的任何进一步调查,您可以使用多种工具。
You can use console.log
and output the values to the terminal (it's not the cleanest approach, but it gives quick results)您可以使用
console.log
和 output 将值发送到终端(这不是最干净的方法,但可以快速得出结果)
You can also show the ID in the component, and see what's going on:您还可以在组件中显示 ID,并查看发生了什么:
<li key={id} className="col-12">
(ID: {id}) - {itype} {dateStamp}
</li>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.