title: Issuing AJAX request in the callback of setState()
body: <p>I have been coding my ReactJS AJAX requests like this:</p>
  
  <pre><code>this.setState({
      isLoading: true,
      results: null
  });
  $.get(ajaxUrl, function(results) {
      this.setState({
          isLoading: false,
          results: results
      });
  }.bind(this));
  </code></pre>
  
  <p>This is just an example, it lacks error handling, throttling, cancelling requests, etc. But the gist is there. I basically ask for some state to be set and <em>then</em> issue a request.</p>
  
  <p>Looking at some other code on GitHub, though, I noticed that some people write their AJAX calls in the setState callback:</p>
  
  <pre><code>this.setState({
      isLoading: true,
      results: null
  }, function() {
      $.get(ajaxUrl, function(results) {
          this.setState({
              isLoading: false,
              results: results
          });
      }.bind(this));
  }.bind(this));
  </code></pre>
  
  <p>Is there a valid reason to do so? <a href="https://facebook.github.io/react/docs/component-api.html" rel="nofollow">The docs say</a>:</p>
  
  <blockquote>
    <p>There is no guarantee of synchronous operation of calls to setState and calls may be batched for performance gains.</p>
  </blockquote>
  
  <p>So there is no guarantee that setState mutates the state before returning, but I see no mention that different setState's may execute out of order. So the worst that could happen is that the "loading" state never gets rendered. Is this what the latter style is trying to solve? Is there some other risk I fail to see?</p>