i am using ionic react with below code. Where i am fetching data from firebase and then trying to set it to a state variable. however it does not seems to set and the code is fairly starightforward. how do i make sure it is set before i can do next operation on this value?
const Tab5: React.FC = () => {
const [coins, setCoins] = useState(0)
useIonViewDidEnter(async() => {
console.log('ionViewDidEnter event fired');
console.log("user data from firebase is", usrVal)
if(usrVal === null || usrVal.coins === undefined){
setCoins(0)
setDiviCoins(0)
}else{
console.log("we are here to set conversion")
setCoins(+usrVal.coins)
console.log("coins after set is::" + usrVal.coins, coins)
}
});
```
logs print like below
```
[log] - user data from firebase is {"coins":553,"theme":{"dark":"rgb(175,8,8)","light":"rgb(255, 255, 255)"}}
⚡️ [log] - we are here to set conversion
⚡️ [log] - coins after set is::553 0
```
i have no idea why setCoins is not working?