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

86
Views
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 answers
Answer question

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 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!