From React’s documentation:
setState()does not immediately mutatethis.statebut creates a
pending state transition. Accessingthis.stateafter calling this
method can potentially return the existing value. There is no
guarantee of synchronous operation of calls tosetStateand calls may
be batched for performance gains.
If you want a function to be executed after the state change occurs, pass it in as a callback.
this.setState({value: event.target.value}, function () {
console.log(this.state.value);
});