正文从这开始~
总览
当我们从map()
方法返回的两个或两个以上的元素具有相同的key
属性时,会产生"Encountered two children with the same key"错误。为了解决该错误,为每个元素的key
属性提供独一无二的值,或者使用索引参数。
![react-encountered-two-children-with-the-same-key.png](https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/bbd038d463fe4e97a901fb9365cb416f~tplv-k3u1fbpfcp-watermark.image?)
这里有个例子来展示错误是如何发生的。
// App.js
const App = () => {
// 标签:name,two,same,Alice,person,报错,key,id,属性
来源: https://www.cnblogs.com/chuckQu/p/16581398.html