警告控制台:列表中的每个 child 在代码 react.js 中的 table 中应该有一个唯一的“键”道具

Warning console : Each child in a list should have a unique “key” prop in table in code react.js

我想更正控制台中的警告“列表中的每个 child 都应该有一个唯一的”键“prop”。我尝试在其中添加道具“rowkey”,“key”,但问题仍然存在。

//***************************** Code ********************************//
class TableOfState extends React.Component {
render() {
const states = this.props.statesList;
const columns = [
//**************** I'm trying to add a column "id" *************************//
{
dataIndex: 'id',
key: 'id',
},
{
title: 'name',
dataIndex: 'name',
key: 'name',
},
{
title: 'Color',
dataIndex: 'color',
key: 'color',
},
];
return (
<div>
<Widget>
  <Row>
      <Table
    //******************* The two solutions that I tried *******************//
        // key={states.id}
        // id={states.id}
        // rowkey={states.idDept}
        dataSource={states}
        columns={columns}
        pagination={true}
        className="gx-table-responsive"
        style={{ width: "100%" }}
      />

       </Row>
    </Widget>
  </div>
)
}
}

这是控制台上的警告::

您需要为所有数据项添加 'key' 具有唯一值的属性

const dataSource = [
  {
    key: '1',
    id: 1,
    name: 'Mike',
    age: 32,
    address: '10 Downing Street',
  },
  {
    key: '2',
    id: 2,
    name: 'John',
    age: 42,
    address: '10 Downing Street',
  },
];

或者如果您的项目已经具有唯一键(例如 'id'),则通过 rowKey 属性为 Table 组件指定它:

<Table dataSource={dataSource} rowKey="id" ... />;