Weird behavior that I can’t explain:
Here’s a react component that shows a stringified object - data from google account.
If I change props.user[0].services
to
props.user[0].services.google
property
I get an error:
Weird behavior that I can’t explain:
Here’s a react component that shows a stringified object - data from google account.
If I change props.user[0].services
to
props.user[0].services.google
property
I get an error:
I cannot see the actual data, but it might be that the services property is loaded after the function call.
On a different topic. To prevent these errors you might want to use lodash’s _.get function. It allows you to give defaults aswell:
const googleProps = _.get(props, 'user[0].services.google', {});
return JSON.stringify(googleProps, null, 4);
Yep, it helps. I’m curious if it’s good practise to get google’s account picture and email that way?
Yup definitely. The way I would approach this is as follows.:
const googleProps = _.get(props, 'user[0].services.google', {
picture: 'https://some-source/default-picture.png',
email: 'unknown'
});