I don't know why 'res' is initialized after calculating in forEach.
console.log in forEach returns the correct value.
however, console.log in useEffect returns only 0.
useEffect(() => {
const addClaimableAmount = () => {
let res = 0;
ENDED.forEach(async value => {
const response = await getEstimatedAPRByStakeId(value.stakeId);
res += parseInt(response.estimatedReward);
res += parseInt(value.amount);
console.log(res);
});
return res;
};
const res = addClaimableAmount();
console.log(res);
}, [ENDED]);