I have created a small react App that presents documents from a SharePoint site.
To make the App work correctly I am having to add setTimeouts, but I know there must be a better way using callbacks or promises or something >.<
My knowledge is lacking, so could somebody please point me in the right direction?
  // Handles what runs when the drop down is changed
  public handleDropdownChange(e) {
    // Updates dropdown select
    this.setState({ selectedOption: e.target.value, isLoading: true });
    // Checks security permissions - MAKES A GET REQUEST
    setTimeout(() => {
      this.getSecurityGroupUsers();
    }, 1000); 
   // Ghecks if user can access docs
    setTimeout(() => {
      this.checkForDocAccess();
    }, 2000); 
    // Gets documents - MAKES A GET REQUEST
    setTimeout(() => {
      this.getDocuments();
    }, 4000); 
    // Delete Mark as Reviewed property THEN displays docs
    setTimeout(() => {
      this.hideMarkAsReviewed();
    }, 8000);
  }
One of the functions:
  // Grabs the documents
  public getDocuments() {
    axios
      .get("https://bpk.sharepoint.com/_api/search/query?querytext='owstaxIdDocumentx0020Owner:" + this.state.selectedOption + "'&trimduplicates=true&rowsperpage=100&rowlimit=1000&selectproperties='LastReviewDateOWSDATE,ScheduledReviewDateOWSDATE,Path'",
        { params:{},
          headers: { 'accept': 'application/json;odata=verbose' }
        })
      .then(response =>
          response.data.d.query.PrimaryQueryResult.RelevantResults.Table.Rows.results.map(document => ({
            Type: this.checkFile(document),
            Name: document.Cells.results[6].Value.split("/").pop(),
            'Scheduled Review Date': document.Cells.results[8].Value.slice(0,-11),
            Path: document.Cells.results[6].Value.replace('https://bpkintelogydev.sharepoint.com', ''),
            Site: document.Cells.results[6].Value.split('/').slice(4).slice(0,1),
            'Last Review Date': document.Cells.results[7].Value.slice(0,-11),
            View: <a href="#" onClick={()=>window.open(document.Cells.results[6].Value + '?web=1&action=edit')}>View</a>,
            'Mark as Reviewed': <a href='#'>Mark</a>
        }))
      )
      .then(documents => {
        this.setState({documents, isLoading: true});
      })
      .catch(error => {
        //console.log(error);
      });
  }
 
     
     
     
    