title: React wait for server response
body: <p>I want to write an application that requests some informations from an API. As long as this informations isn't available I don't want to continue with the rest of the application. I already tried this:</p>
  
  <pre><code>function suggestion(callback) {
      xhr.open('GET', 'http://localhost:3001/');
      xhr.onload = function() {
          var a = JSON.parse(xhr.responseText);
          console.log(a);
          callback(a);
      };
      xhr.send();
  }
  
  var sugg = suggestion(function(lista) {
      var s = [];
      lista.forEach(element =&gt; {
          s.push(element.event);
      });  
      console.log(s);
  
      return s; 
  });
  </code></pre>
  
  <p>Why sugg is returning undefined?</p>