title: How to use Promise.all in react js ES6
body: <p>What i want to do is to upload file on server, then get URL of uploaded file and preview it. Files can be more than one. For that purpose i have written following code:  </p>
  
  <pre><code> let filesURL=[];
   let promises=[];
   if(this.state.files_to_upload.length&gt;0) {
  
      for(let i=0; i&lt;this.state.files_to_upload.length; i++) {
          promises.push(this.uploadFilesOnServer(this.state.files_to_upload[i]))
      }
  
      Promise.all(promises).then(function(result){
          console.log(result);
          result.map((file)=&gt;{
              filesURL.push(file);
          });
      });
      console.log(filesURL);
  }
  const uploadedFilesURL=filesURL;
  console.log(uploadedFilesURL);
  </code></pre>
  
  <p><code>console.log(filesURL);</code> give me the values returned by <code>Promise.all</code>.<br>
  And i want to use these values only when <code>Promise.all</code> completes properly. But, i am facing problem that lines <code>console.log(uploadedFilesURL);</code> excutes first irrespective of <code>Promise.all</code> and give me <code>undefined</code> values.I think i am not using promises correctly, can anyone please help me?<br>
  <code>uploadFileOnServer</code> code is:  </p>
  
  <pre><code>uploadFilesOnServer(file)
    {
      let files=[];
      let file_id='';
  
      const image=file;
      getImageUrl().then((response) =&gt; {
        const data = new FormData();
        data.append('file-0', image);
        const {upload_url}  = JSON.parse(response);
        console.log(upload_url);
  
        updateProfileImage(upload_url, data).then ((response2) =&gt; {
        const data2 = JSON.parse(response2);
        file_id=data2;
        console.log(file_id);
        files.push(file_id);
        console.log(files);
          });
      });
      return files;
    }
  </code></pre>