Warning: Each child in an array or iterator should have a unique "key" prop
This might be silly but an array of JSON data throws this warning.
Hi @laurenamy,
This warn is not easily to find out, it happens when use map and didn't given key props, anyway if you have happened again, you may take a picture here, Thanks ~
Hi @madeinfree,
The warning I'm experiencing occurs since v 2.3.8. No warning in v 2.3.7.
Warning: flattenChildren(...): Encountered two children with the same key, Abc. Child keys must be unique; when two children share a key, only the first child will be used.
in tbody (created by TableBody)
in table (created by TableBody)
in div (created by TableBody)
in TableBody (created by BootstrapTable)
in div (created by BootstrapTable)
in div (created by BootstrapTable)
in BootstrapTable
@microdou Thanks, I'll check it later !
Sorry for lately reply. Any sample code can reproduce this issue? Thanks :)
I have encountered this problem when using array of objects that returns map. The solution I made is to convert it. I'm not sure if this is a good solution, but it works in my case.
var arrList=[];
objects.map((obj) =>
{ var a = {
prop1 : obj.get("prop1"),
prop2 : obj.get("prop2"),
n : obj.get("n")
};
arrList.push(a);
}
);
@laurenamy, the snippet you show up is that your solution?
@AllenFang
It appears that now a unique value is somehow required in each object of the data array since v2.3.8. This unique value is used to provide a unique Key in Table. When values in a dataField are not unique, error occurs.
My previous data array and TableHeaderColumn:
Data = [
{name:"apple"},
{name:"orange"},
{name:"orange"},
]
<BootstrapTable data={Data}>
<TableHeaderColumn dataField="name" isKey={true}>Name</TableHeaderColumn>
</BootstrapTable>
Unique id is added to new data, and is set as key via isKey={true}. Error and warnings are now gone.
Data = [
{id: 0, name:"apple"},
{id: 1, name:"orange"},
{id: 2, name:"orange"},
]
<BootstrapTable data={Data}>
<TableHeaderColumn dataField="id" isKey={true}>Name</TableHeaderColumn>
<TableHeaderColumn dataField="name">Name</TableHeaderColumn>
</BootstrapTable>
@microdou, I got it. Actually, if isKey been applied, you should ensure the key column should not duplicated. If there's no any unique columns, I suggest you generate a set of sequence number to applied as key column.