submit = () => {
this.checkValidation();
console.log(this.state.isError) //this is not giving updated value
}
checkValidation = () => {
this.setState({
isError: true
})
}
>Solution :
You can callback funtion to access the updated state right after setting it,
this.setState({ isError: true }, this.logState)
logState = () => {
console.log(this.state.isError)
};
In your case you can either move the setting of state inside the submit function or return the updated the updated value from checkValidation function and then set the state within submit function :
submit = () => {
this.checkValidation();
setState(
{ isError: true },
() => console.log(this.state.isError)
);
}