I have a component that works and will return data from State as long as it isn't nested. However, if I need to dig a little deeper within the object, I get an error: "TypeError: Cannot read property 'name' of undefined".
I'm positive that there is a value for it (checked Inspector and the variable does indeed have a value, that's how I knew what to put in code). Why does it work for a higher value, but not the lower value?
class Concert extends Component {
constructor(props) {
super(props);
this.state = ({
concert:''
})
}
componentDidMount(){
var concertid = `${REQ_URL}/${this.props.match.params.concertid}`;
fetch(concertid, {
method: 'GET'
})
.then(response => response.json())
.then(json => {
this.setState({
concert:json
})
})
}
render() {
return (
<div>
<Header />
<div className="concert">
<div className="venue">
//THIS IS THE PART THAT RETURNS ERROR
//this.state.concert.id returns a correct value
//POSITIVE this.state.concert.artist.name DOES CONTAIN VALUE
Venue: {this.state.concert.artist.name}
</div>
</div>
</div>
)
}
}