Skip to content
Advertisement

how to use value of useState after init it

I these state hook:

JavaScript

my medicalProblem variable will initial with response of a api :

JavaScript

but I got this error:

JavaScript

Advertisement

Answer

There are a couple ways to accomplish this, but the easiest may be creating another useEffect hook that depends on the medicalProblems array as seen below!

JavaScript

That extra hook will make sure your medicalProblems are populated before proceeding to initialize your features. Let me know if this works!

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement