In your example, it isn’t saying that myData
is undefined, it’s saying that it can’t read the property myData
of undefined. I.e the state
property of location
is undefined.
componentDidMount() {
if (this.props.location.state === undefined) {
this.props.history.push('/');
return;
}
// else
}
CLICK HERE to find out more related problems solutions.