哇偶 报错了 Each child in a list should have a unique "key" prop

来源:3-4 【组件化】初识React函数式组件

i杨永安

2021-03-31

index.js:1 Warning: Each child in a list should have a unique “key” prop.

Check the render method of App. See https://reactjs.org/link/warning-keys for more information.
at Robot (http://localhost:3000/static/js/main.chunk.js:290:3)
at App
图片描述

写回答

1回答

阿莱克斯刘

2021-04-06

这个报错解决很简单,请在for循环的组件中加上key就好了,如图所示

function App() {
  return (
    <ul>
      {robots.map((r, index) => (
         <Robot key={index} id={r.id} email={r.email} name={r.name} />
      ))}
    </ul>
  );
}

//img.mukewang.com/szimg/606b55f6097434b918000570.jpg

0
1
i杨永安
非常感谢!
2021-04-06
共1条回复

React18 系统精讲 结合TS打造旅游电商平台

React18 精讲 + 结合 TS 实战 + 热门业务开发,获取必备技能

1993 学习 · 1015 问题

查看课程