解决警告Warning: Each child in a list should have a unique “key” prop.

 浆糊之家   2019-08-18 10:27   0 views 热度值  网名www.fybqq.com

常常写react代码,一不小心就会报如下错误,

Warning: Each child in a list should have a unique "key" prop.

Check the render method of ProductTable. See https://fb.me/react-warning-keys for more information.

解决警告Warning: Each child in a list should have a unique

解决警告Warning: Each child in a list should have a unique "key" prop.

基本都是因为在循环生成多个组件的时候,没有给组件加上key引起的,因为dom进行diff对比 没有key值,所以报错警告。。

此时我们需要循环生成多个组件中,加上key值(唯一值)那么就不会报错了,虽然不起眼的bug,但是特别容易范这类低级失误

 

例如如下:

 

 

NEXT:已经是最新一篇了

 发表评论


表情