Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

156
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda