I want to change the value for the hasSubmit key, like in the First Code section. I know this is not recommended. But the second code is asynchronous and I don't want to use the callback function of setState.
- What is the difference of
this.stateandsetState? - Is there any way to change state value
hasSubmitimmediately?
First Code:
this.state.hasSubmit = false
this.setState({})
//Code that will use `hasSubmit`.
Second code:
this.setState({
hasSubmit: false,
});
//Code that will use `hasSubmit`.
ADD:
The scenario is that:
hasSubmitsetfalseingetInitialState().hasSubmitwill change tofalsewhen I clicksubmitbutton.hasSubmitwill change totruewhen submitted.
First click submit has no problem and hasSubmit will be set to true.
But second click submit will be wrong using the Second asynchronous code, because the hasSubmit is still true, while the First Code can resolve the problem.