(Meteor 1.3 & React) TypeError in IF statement on undefined variable/prop


#1

Hi.

I am getting a TypeError when I want to check on a prop value. In this case, for new users the profile.email prop does not exist and should return a true since it is undefined (profileEmail has been declared btw).

if (!this.props.user.profile.email){ profileEmail = this.props.user.emails[0].address; } else { profileEmail = this.props.user.profile.email; }

However I get the following in the console:
TypeError: Cannot read property 'emails' of undefined

That is right since it is undefined for new users (which is how I am testing), but shouldn’t the conditional return a true and move on to getting the user’s email address from the emails array (when users register using email using Accounts)?

I have tried the following statements and none seem to work:
(this.props.user.email === undefined) (typeof this.props.user.email === 'undefined') (this.props.user.email)

The latter is a reverse check, but still no luck. Thoughts or tips anyone?