Closed singhmi4 closed 3 years ago
Hey @singhmi4 hmmm I wish user
wasn't embedded in userData
so that it would be easier to identify if the user is already loaded. I guess regardless what you can do on that page is to wrap it around a logic that guarentees that user
is not undefined before it loads for example
{userData.user && (
<Grid item>
<Typography>{userData.user.firstName} {userData.user.lastName}</Typography>
...
)}
hi @bonnieli that Inline If with Logical && Operator
got it to work, thanks!
As for your suggestion about not having user
embedded into the userData object, that's because in the UserProvider context file, I have setUser({ authenticated: true, user: responseJson.user })
which is what gets set after the successful authentication process from the back-end.
I'm getting stuck on getting the data from UserProvider.context to display user data on the dashboard because it's giving me a similar undefined error I got on the New Events page. The difference here is that the page expects to load the data right away as opposed to having to click a button to retrieve the data as in the New Events page.
Error Message:
Is there a react method that waits for context data to load before rendering the components from using it? I tried using a ternary operation below to check if undefined:
but that isn't making the error go away. I tried looking on stack overflow, but not finding anything that can help at the moment.