devScripts.js:5836 Warning: Each child in a list should have a unique "key" prop.
Check the top-level render call using <div>. See https://fb.me/react-warning-keys for more information
in Fragment
in Unknown (created by Context.Consumer)
in Route (created by Context.Consumer)
in Switch (created by Context.Consumer)
in main (created by Basic)
in Basic (created by Content)
我的代码结构:
manageTypeList.map((item: manageTypeResponseType, index: number)=>(<>
<div className="h_p_m_content_item" key={index}></div>
</>))
在浏览器中找了不少都是说没有key的错误,但是我已经在代码中加了一个key,索性就直接看自己的代码以及报错信息了,突然想到加了一个空的标签<></>,其实这个空标签是一个React.Fragment
的一个语法糖,可以加上一个key的属性,于是我就将这个<></>移除就没有报错了!也可以在<></>上加一个key。