问题描述
devScripts.js:6523 Warning: Each child in a list should have a unique "key" prop.
Check the render method of `Body`. See https://reactjs.org/link/warning-keys for more information.
at BodyRow (http://**:8000/umi.js:392823:25)
in Body (created by Table)
in table (created by Table)
in div (created by Table)
in div (created by Table)
问题截图

问题分析
Check the render method of 'Body'.,Table 组件没有加 rowKey 导致
问题解决
// 为 rowKey 属性赋值
<Table dataSource={data} rowKey={(record) => record.id}>
// ...
</Table>
问题消失 nice~
附:如果id不能保证唯一,可以使用index, 或者随机数 // 注意更新时不可用
# index 使用方式
index.toString()
# 随机生成数方式:
# 1.JavaScript random() 方法
# Math.rando

文章主要讨论了在React中遇到的关于列表子项缺少唯一`key`属性的警告,指出问题出在`Body`组件的渲染方法上。解决方案是为`Table`组件添加`rowKey`属性,可以使用记录的`id`作为唯一标识,如果`id`不唯一,则可考虑使用`index`或随机数。但需要注意,`index`和基于时间戳的随机数在数据更新时可能不可靠。

974

被折叠的 条评论
为什么被折叠?



