简体   繁体   English

我收到错误列表中的每个孩子都应该有一个唯一的“关键”道具

[英]i am getting error Each child in a list should have a unique "key" prop

i am using react and when i tried to use map function in it,i had multiple components inside map return function.so inorder to contain i used dummy parent element and started showing the error ** Each child in a list should have a unique "key" prop**.i don't know how to include key in the dummy parent <>.will you help me out. i am using react and when i tried to use map function in it,i had multiple components inside map return function.so inorder to contain i used dummy parent element and started showing the error ** Each child in a list should have a unique " key” prop**。我不知道如何在虚拟父 <> 中包含 key。你能帮帮我吗?

                           {
                             dataArray.map((item,key)=>{
                                return(
                                     <>

                                    <td key={key}>{item.country}</td>
                                     <td key={key}>{item.city}</td>
                                    </> 
                                )})
                            }



By adding the dummy parent i am getting that error unique key.is there any way i can remove the unique key error keeping both td in the return statement通过添加虚拟父级,我得到了唯一键错误。有什么方法可以删除唯一键错误,同时将 td 保留在 return 语句中

Add a key to the fragment , not to the individual <td> s:将键添加到片段,而不是单个<td> s:

{
  dataArray.map((item, key) => {
    return (
      <React.Fragment key={key}>
        <td>{item.country}</td>
        <td>{item.city}</td>
      </React.Fragment>
    );
  })
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 列表中的每个孩子都应该有一个唯一的“关键”道具,我在我的反应原生应用程序中遇到了这个错误 - Each child in a list should have a unique "key" prop, I am getting this error in my react native app 反应错误:列表中的每个孩子都应该有一个唯一的“关键”道具 - React Error: Each child in a list should have a unique "key" prop ESLint 错误:列表中的每个孩子都应该有一个唯一的“key”道具 - ESLint Error: Each child in a list should have a unique “key” prop 列表中的每个孩子都应该有一个唯一的“关键”道具控制台错误 - Each child in a list should have a unique "key" prop console error 列表中的每个孩子都应该有一个唯一的“关键”道具。 即使我给了一把钥匙,而且它是独一无二的 - Each child in a list should have a unique “key” prop. Even though i am giving a key and its a unique one 列表中的每个孩子都应该有一个唯一的“关键”道具。 我做到了,但仍然看到这个错误 - Each child in a list should have a unique "key" prop. I made it, but still see this error 修复警告 ///列表中的每个孩子都应该有一个唯一的“键”道具 - fixing warning ///Each child in a list should have a unique "key" prop Reactjs:警告列表中的每个孩子都应该有一个唯一的“关键”道具 - Reactjs: Warning Each child in a list should have a unique "key" prop 警告:列表中的每个孩子都应该有一个唯一的“键”道具来切换 - Warning: Each child in a list should have a unique "key" prop for switch “反应”列表中的每个孩子都应该有一个唯一的“关键”道具 - "react" Each child in a list should have a unique "key" prop
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM