I have a user profile page in my Meteor application that is built using React components. Since it uses Meteor.user () to create one of the variables, I get an error message when I exit the application (but only if I visited the profile page in the current session earlier). This makes sense to me, because without the current user, Meteor.user () is no longer available, so it will fail with the message "cannot read" undefined messages.
AccountList = React.createClass({
mixins: [ReactMeteorData],
getMeteorData(){
var user;
var supportingUserId = Meteor.user().support.supportingUserId;
supportingUserId ? user = Meteor.users.findOne({_id: supportingUserId}) : user = Meteor.user();
return {
accounts: Accounts.find({owner: user._id}).fetch()
}
}...
At first I tried to change the above code block to wrap the violation code in an if statement as follows:
AccountList = React.createClass({
mixins: [ReactMeteorData],
getMeteorData(){
var user;
if (Meteor.user()){
var supportingUserId = Meteor.user().support.supportingUserId;
supportingUserId ? user = Meteor.users.findOne({_id: supportingUserId}) : user = Meteor.user();
return {
accounts: Accounts.find({owner: user._id}).fetch()
}
}
else{
return {};
}
}...
: " " undefined ", ( , " "). if, . , if (Meteor.user()). , , React ?