Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Countdown component renders before value is fetched from asyncStorage: NaN #89

Open
fokke-m opened this issue Oct 2, 2020 · 0 comments

Comments

@fokke-m
Copy link

fokke-m commented Oct 2, 2020

Hello,
I want to to get the countdown until value from an asyncStorage object. But it seems the countdown component renders before the asyncStorage.getItem is being fetched.

This is how I get the asyncStorage item:

 const [appAssessment, setAppAssessment] = useState({});

AsyncStorage.getItem('appAssessment').then(data => {
    const assessment = JSON.parse(data);
    setAppAssessment(assessment);
  });

and then I insert an appAssessment.duration value in the until property of the countdown component like so:

until={Number(appAssessment.duration)}

The countdown timer always renders NaN. However, I also use this duration property in one of my other components as well and there it shows perfectly. It seems like I get this NaN value because it's still empty when the countdown component is being rendered. How can I solve this?

Also: the running option doesn't seem to work either, when i set state to false it keeps running...
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant