简体   繁体   English

如何在反应列表中的每个孩子中添加唯一的关键道具?

[英]how can I add unique key prop in each child in a list on react?

I keep getting this error我一直收到这个错误

I am trying to solve this warning.我正在尝试解决此警告。

If movies don't have an id and you just want to get rid of the warning, you can use the second argument of the map function, which returns the index:如果电影没有 id 而你只是想摆脱警告,你可以使用 map 的第二个参数 function,它返回索引:

movieDB[movie].map((movies, index) => {
  <li className='items' key={index}>
    ...
  </li>
})

I think that every movie name is unique, so you can just我认为每一部电影的名字都是独一无二的,所以你可以

<li classname='items' key={movies.name}>

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

相关问题 列表中的每个孩子都应该有一个唯一的“关键”道具/反应 - Each child in a list should have a unique "key" prop / react 反应错误:列表中的每个孩子都应该有一个唯一的“关键”道具 - React Error: Each child in a list should have a unique "key" prop React - 列表中的每个孩子都应该有一个唯一的“key”道具 - React - Each child in a list should have a unique “key” prop 反应警告:列表中的每个孩子都应该有一个唯一的“关键”道具 - React Warning: Each child in a list should have a unique "key" prop React - 警告:列表中的每个孩子都应该有一个唯一的“key”道具 - React - Warning: Each child in a list should have a unique “key” prop 反应错误:列表中的每个孩子都应该有一个唯一的“关键”道具 - React error: Each child in a list should have a unique "key" prop React - 列表中的每个孩子都应该有一个唯一的“key”道具 - React - Each child in a list should have a unique 'key' prop React:列表中的每个孩子都应该有一个唯一的“key”道具 - React: Each child in a list should have a unique “key” prop 反应错误:列表中的每个孩子都应该有一个唯一的关键道具 - React Error: Each child in a list should have a unique key prop “反应”列表中的每个孩子都应该有一个唯一的“关键”道具 - "react" Each child in a list should have a unique "key" prop
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM