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

74
Visualizações
State not getting updated in promises

I have below states -

   const[value1,setValue1]=useState();
    const[value2,setValue2]=useState();
    
    function promiseExecutionMethod()
    {
      let Value1Promise=Collection.fetValue()
                                 .then((res)=>
                                          { 
                                             setValue1(res); 
                                           });
    
    let Value2Promise=Collection.fetValue()
                                 .then((res)=>
                                          { 
                                             setValue2(res); 
                                           });

Promise.all([Value1Promise,Value2Promise]).then(([result1,result2])=>{
  console.log(value1);   //cannot see updated states here
  console.log(value2);   //cannot see updated states here
}


    }

useEffect(()=>{
console.log(value1); //can see updated state
},[value1]);

useEffect(()=>{
console.log(value2); //can see updated state
},[value2]);

Here I am changing states in promise. UseEffect also shows changed states.

But not able to see changed states in Promise.All(..).Then method.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I made use of another state -

const[render,setRender]=useState(0);

and in Promise.all([..]).then(([..])

Promise.All([Value1Promise,Value2Promise]).then(([result1,result2])=>{
  setRender(render+1);
}

Through this , I am able to access updated states.

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