This is my code inside a component.
this.state = {
strength: 0,
dexterity: 0,
intelligence: 0,
health: 0
};
this.increaseBasicAttrStrength = this.increaseBasicAttrStrength.bind(this);
this.updateApp = this.updateApp.bind(this);
}
increaseBasicAttrStrength(event) {
this.setState(prevState => ({
strength: prevState.strength + 10,
dexterity: prevState.dexterity,
intelligence: prevState.intelligence,
health: prevState.health
}));
this.updateApp();
}
updateApp() {
console.log(this.state);
this.props.basicAttrsHandler(this.state);
}
Even though updateApp(...) called after increaseBasicAttrStrength(...), when i console the state it shows as below.
{strength: 0, dexterity: 0, intelligence: 0, health: 0}
state has not updated.