I'm building a react app that uses data fetched from an API, but the problem is that I can't seem to display the data properly. Here is how I am reading the API file in my app
fetch(url)
.then(response => response.json())
.then(data => {
if (data) {
var temp = this.state.ObjectData
temp.push(data)
this.setState({ObjectData: temp})
}
})
.catch(console.log)
And here is what the constructor looks like in my app
constructor(){
super()
this.state = {
ObjectData: []
}
}
It looks like I'm reading in the API correctly as when I try to use console.log(this.state.ObjectData)
I get a '[]' that drops down to '0' and then followed by the first element in the object which for the API file I'm reading would be abilities. But if I do console.log(this.state.ObjectData[0].abilities)
I get undefined
in the console log