Sunny, excellent article on context! This is something I have been struggling with a lot lately. I'm running into an issue where I'm fetching data from an API and loading it into context to use in my app. But my app tries to use the data before it's available and getting 'undefined' errors. Any ideas how to overcome this? Looks like miodrag is having a similar issue.
Thanks Mike! It's ok for the data to be undefined before it's available, that's how you are able to detect loading states. I suggest you return some default content or a loading spinner in your component's render so that the rest of the component does not try to reference something like data.user.name before it's set.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Sunny, excellent article on context! This is something I have been struggling with a lot lately. I'm running into an issue where I'm fetching data from an API and loading it into context to use in my app. But my app tries to use the data before it's available and getting 'undefined' errors. Any ideas how to overcome this? Looks like miodrag is having a similar issue.
Thanks Mike! It's ok for the data to be undefined before it's available, that's how you are able to detect loading states. I suggest you return some default content or a loading spinner in your component's render so that the rest of the component does not try to reference something like
data.user.name
before it's set.