I have a list of items I am rendering inside my render method (conveniently, actually named Item).
render() {
return (
<div>
{
this.state.items.map(item => (
<Item
id={item.id}
myValue={item.myValue}
updateItem={this.handleUpdateItem}
deleteItem={this.handleDeleteItem}
/>
))
}
</div>
)
}
This works, but I get the warning that Each child in a list should have a unique "key" prop
. However, adding the key prop causes an error.
render() {
return (
<div>
{
this.state.items.map(item => (
<Item
id={item.id}
key={item.id}
myValue={item.myValue}
updateItem={this.handleUpdateItem}
deleteItem={this.handleDeleteItem}
/>
))
}
</div>
)
}
The error:
Uncaught Invariant Violation: Objects are not valid as a React child (found: object with keys {myValue}). If you meant to render a collection of children, use an array instead.
This error only happens on update, when I change the myValue of an item. The initial page loads just fine.
Could someone help me understand what's going on here?