0

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]);
Mehdi
  • 385
  • 1
  • 12
Jerry
  • 41
  • 1
  • 6

0 Answers0