title: Synchronous fetch - ReactJS
body: <p>In a function I loop, in which I’m making fetch calls.
  When all calls are finished, I need to save the values in a variable, but that’s not being possible for me to be asynchronous to the calls.</p>
  <pre><code>getReportsGroup(bukrs){
          
      //TOTAL OF A PROJECT GROUP
      fetch('api/Reports/GetDataIRPA?SETCLASS=' + this.state.SETCLASS, {
          method: 'GET',
          headers: {
              'Accept': 'application/json',
              'Content-Type': 'application/json',
          }
      })
      .then(response =&gt; response.json())
      .then(data =&gt; {
         this.setState({
             reportIRPA: data
         });
       });
  }
  
  getTotalProjects(){
     //Browse selected projects
     for (var i = 0; i &lt; this.state.selectProjects.length; i++) {
         this.getReportsGroup(this.state.selectProjects[i].bukrs);
     }
      
     console.log('finish all fetch');
  }
  </code></pre>
  <p>The <code>getTotalProjects</code> function is performing a loop in which <code>getReportsGroup</code> is called (fetch is made here). At the end of all fetchs I need to display a message in <code>getTotalProjects</code>. Currently, being asynchronous, it performs the <code>console.log('finish all fetch')</code> before finishing all fetch.</p>