Each record in table should have a unique `key` prop,or set `rowKey` to an unique primary key.
See original GitHub issueI’m trying to figure out how can I get unique keys for each record.
So far, my code looks like this:
let lastIndex = 0
const updateIndex = () => {
lastIndex++
return lastIndex
}
...
constructor() {
super()
this.state = {
columns: [ {
title: 'Nombre',
dataIndex: 'name',
key: `name${updateIndex()}`
}, {
title: 'Precio',
dataIndex: 'price',
key: `price${updateIndex()}`
}, {
title: 'Precio regular',
dataIndex: 'regularPrice',
key: `regularPrice${updateIndex()}`
}, {
title: 'Categoría(s)',
key: `id${updateIndex()}`,
render: (text, record) => (
<span>
{
record.categories.map((r, index) => (
<span key={index}>
{
index > 0 &&
<span className="ant-divider"/>
}
<span>{r.name}</span>
</span>
))
}
</span>
)
}, {
title: 'Action',
key: `id${updateIndex()}`,
render: (text, record) => (
<span>
<a href="#">Editar - {record.name}</a>
<span className="ant-divider"/>
<a href="#" style={{color: 'red'}}>Borrar</a>
</span>
)
}, ]
}
}
But I’m still getting the error that each record in table should have a unique key
.
What would be the best way to achieve this?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:9
- Comments:30 (2 by maintainers)
Top Results From Across the Web
Each record in table should have a unique `key` prop,or set ...
Each record in table should have a unique key prop,or set rowKey to an unique primary key. solution 1. each col has a...
Read more >antdv: Each record in table should have a unique `key` prop,or ...
antdv: Each record in table should have a unique `key` prop,or set `rowKey` to an unique primary key ; 3. 点赞 ; 踩...
Read more >Table - Ant Design
According to the React documentation, every child in an array should be assigned a unique key. The values inside the Table's dataSource and...
Read more >Each record in table should have a unique `key` prop,or set ...
Each record in table should have a unique `key` prop,or set `rowKey` ... in table should have a unique `key` prop,or set `rowKey`...
Read more >Each record in table should have a unique `key` prop,or set ...
Coding example for the question Each record in table should have a unique `key` prop,or set `rowKey` to an unique primary key-Reactjs.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@ahmetkuslular The error message is pretty explicit your data set must contain items with a key property on them or you must specify the rowKey property on the Table component with the name from a field in your dataset which is unique to each row.
Source Code Here
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:
My data had “id” instead:
In order to resolve this, I added a rowKey property to my Table like so: