I am attempting to fetch data from this NHL API: https://statsapi.web.nhl.com/api/v1/people/8477474/
When i output the call to my page it returns undefined and i can't get it to display the value. Oddly enough, the first element in the object displays correctly but not any of the nested elements.
Here is my code
import React, {Component} from "react"
class App extends Component {
constructor() {
super()
this.state = {
loading: false,
player: {}
}
}
componentDidMount() {
this.setState({loading: true})
fetch("https://statsapi.web.nhl.com/api/v1/people/8477474/")
.then(response => response.json())
.then(data => {
this.setState({
loading: false,
player: data
})
})
}
render() {
const fullname = this.state.loading ? "Loading..." : this.state.player.people[0].fullName;
return (
<div>
{fullname }
</div>
)
}
}
export default App
This is not supposed to return undefined, because the key value is clearly there and i believe i am targeting it right.
I tried console logging but i also get undefined. I tried as well removing the [0] and doing this.state.player.people.fullName and all kinds of alternatives but no luck.