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