Just a simple question here, I'm using ASP.NET Web API and ReactJS, and the instrument for reading JSON I'm currently using Axios, this is my JSON data:
[
{
"id": 1,
"name": "Count Duck",
"age": 3
},
{
"id": 4,
"name": "Count Dracula",
"age": 288
},
{
"id": 5,
"name": "Frankenstein",
"age": 45
},
{
"id": 6,
"name": "Frankenstein",
"age": 45
},
{
"id": 7,
"name": "Frankenstein",
"age": 45
},
{
"id": 8,
"name": "Frankenstein",
"age": 45
},
{
"id": 9,
"name": "Frankenstein",
"age": 45
},
{
"id": 10,
"name": "Frankenstein",
"age": 45
},
{
"id": 11,
"name": "Frankenstein",
"age": 45
},
{
"id": 12,
"name": "Frankenstein",
"age": 45
},
{
"id": 13,
"name": "Frankenstein",
"age": 45
}
]
This is my axios request:
async getDataAxios(){
const response = await axios.get("https://localhost:5001/monsters");
const data = await response.data;
this.setState({ monsters: data, loading: false });
console.log(data);
} catch(err) {
console.log(err)
}
}
currently I'm using this, but I get an error: (Uncaught TypeError: Cannot read property 'name' of undefined)
static renderMonstersTable(monsters) {
return (
<table className='table table-striped' aria-labelledby="tabelLabel">
<thead>
<tr>
<th>Username</th>
<th>Image</th>
</tr>
</thead>
<tbody>
{monsters.map(({items}) =>
<tr key="">
<td>{items.name}</td>
<td>{items.age}</td>
</tr>
)}
</tbody>
</table>
);
}
Any help or correction would be appreciated!