I have this json
and I was wondering if there is a way to render a list without having to specify a key.
Here's what I tried:
import * as data from "./file.json";
const nameComponent = props => {
const names = data.locale.names
return(
names.map = name => {
<Item>
<IdName>{name.id}</IdName>
<FirstName>{name.firstName}</FirstName>
<LastName>{name.lastName}</LastName>
</Item>
)
}
I can also just add the keys but I'm getting the following error:
Warning: Each child in a list should have a unique "key" prop.
Why am I getting this error even if I specified the keys?
Like this:
return(
names.map = name => {
<Item key={name.id}>
<IdName>{name.id}</IdName>
<FirstName>{name.firstName}</FirstName>
<LastName>{name.lastName}</LastName>
</Item>
)
EDIT: I have tried the answers below, none of them worked.
The json looks like this:
"items": [
{
"id": 1,
"firstName": "Alan",
"lastName": "Smith"
},
{
"id": 2,
"firstName": "John",
"lastName": "Something"
}
]