Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

155
Views
JS - After Do-While loop, the rest of the function doesnt execute
loadNewPages = async () => {   //TODO this needs to be looping   
    this.setState({ pageCount: 3 })
    let response;
    
    do { response = await getMembers(this.state.pageCount++, this.state.size*3, this.state.divisionFilter, true),console.log(response)}
    while (response.status != 204)
    console.log("finished")
    console.log(this.props.members)
    this.handleRefresh()
        
    
  }

This code is lazy loading data from a database. The do while loop is getting an amount of data and checking if more pages are available before re-executing. Once the response status indicates no more pages the code below should execute, However it does not.

is this a react-js thing or am i just stupid.

Thanks in advance

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

The comma before console.log(response) should be replaced by a semicolon, since it's making response be equal to the last value in the comma chain. Since console.log returns undefined, response is undefined, so undefined.status is always not equal to 204. Therefore it will loop forever.

do { response = await getMembers(this.state.pageCount++, this.state.size*3, this.state.divisionFilter, true); console.log(response)}
while (response.status != 204)
about 4 years ago · Juan Pablo Isaza Report

0

I have found the issue, which was partly my own fault. i was setting a response status 204, which denoted the end of the pages. to reject against the promise. which spit out an error and therefore interrupting the execution of the rest of the function.

TeeHee :P

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!