Does React keep the order for state updates? : <p>I know that React may perform state updates asynchronously and in batch for performance optimization. Therefore you can never trust the state to be updated after having called <code>setState</code>. But can you trust React to <strong>update the state in the same order as <code>setState</code> is called</strong> for</p>

<ol>
<li>the same component?</li>
<li>different components?</li>
</ol>

<p>Consider clicking the button in the following examples:</p>

<p><strong>1.</strong> Is there ever a possibility that <strong>a is false and b is true</strong> for:</p>

<pre><code>class Container extends React.Component {
  constructor(props) {
    super(props);
    this.state = { a: false, b: false };
  }

  render() {
    return &lt;Button onClick={this.handleClick}/&gt;
  }

  handleClick = () =&gt; {
    this.setState({ a: true });
    this.setState({ b: true });
  }
}
</code></pre>

<p><strong>2.</strong> Is there ever a possibility that <strong>a is false and b is true</strong> for:</p>

<pre><code>class SuperContainer extends React.Component {
  constructor(props) {
    super(props);
    this.state = { a: false };
  }

  render() {
    return &lt;Container setParentState={this.setState.bind(this)}/&gt;
  }
}

class Container extends React.Component {
  constructor(props) {
    super(props);
    this.state = { b: false };
  }

  render() {
    return &lt;Button onClick={this.handleClick}/&gt;
  }

  handleClick = () =&gt; {
    this.props.setParentState({ a: true });
    this.setState({ b: true });
  }
}
</code></pre>

<p>Keep in mind that these are extreme simplifications of my use case. I realize that I can do this differently, e.g. updating both state params at the same time in example 1, as well as performing the second state update in a callback to the first state update in example 2. However, this is not my question, and I am only interested in if there is a well defined way that React performs these state updates, nothing else.</p>

<p>Any answer backed up by documentation is greatly appreciated.</p>
