Warning: Each record in table should have a unique `key` prop,or set `rowKey` to an unique primary k

antd使用Table报错,

报错:Warning: Each record in table should have a unique `key` prop,or set `rowKey` to an unique primary key.

解决方法:

This one was confusing to me as well, because I was confusing COLUMN keys with ROW keys. This error has nothing to do with "key" in your column config.

Ant is expecting you to have a unique key specifically named "key" on each row of data, like so:

{ key: 1, value: 'foo'}

My data had "id" instead:

{ id: 1, value: 'foo'}

In order to resolve this, I added a rowKey property to my Table like so:

<Table columns={this.columns} dataSource={this.state.results} rowKey='id' />

https://github.com/ant-design/ant-design/issues/7623

意思就是:这个报错是说需要对dataSource的行加key,不是对列加key,同时这里的rowKey需要使用行的唯一的属性名,不能使用不唯一的属性名或不存在的属性名,不然还是报那个错。列是否加key均可。

如果使用不唯一的属性名作为行key,则报错如下:

Warning: Encountered two children with the same key, `XXX`. Keys should be unique so that components maintain their identity across updates.

如果使用不存在的属性名作为行key,则报错如下:

Warning: Each record in table should have a unique `key` prop,or set `rowKey` to an unique primary key.

 

更多企业内的技术应用和使用技巧,请移步至我的公众号【程序员实用技能】

图片

 

相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页