'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



Solution 1:[1]

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)

Solution 2:[2]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Samathingamajig
Solution 2 freercurse