I've experimented some cases in which calling this.setState({ foo: true }) and immediately checking this.state.foo does not return the new value true.
I can't tell now the exact case in which this happens (maybe when calling multiple times to setState() in the same iteration, I don't know). So I wonder:
Does reactjs guarantee that the following will always work?
this.setState({ foo: true });
console.log(this.state.foo);
// => prints true
this.setStateis an asynchronous operation, so there are no guarantees. They do state this in the official docs.