Why my values under this.props
and this.state
are undefined in my componentDidMount
method? In other parts of my class component I can access my props and state values correctly. Do I need to pass them separately to somewhere or where have I made any mistakes?
There I get no values:
componentDidMount() {
console.log(this.props.token)
console.log(this.state.training.coach)
// values are null and undefined.
if (this.props.token == this.state.training.coach) {
this.setState({
iscreator: true
});
console.log(this.state.iscreator)
} else {
this.setState({
iscreator: false
});
}
}
There I get correct values when accessing this.props.token
:
handleDelete = (event) => {
if (this.props.token !== null) {
const trainingID = this.props.match.params.trainingID;
axios.defaults.headers = {
"Content-Type": "application/json",
Authorization: this.props.token
}
axios.delete(`http://127.0.0.1:8000/api/${trainingID}/`)
this.props.history.push('/');
this.forceUpdate();
} else {
}
}