Skip to content Skip to sidebar Skip to footer

Currentuser Is Displayed Undefined

When i signup, I am redirected to /dashboard page which has Navbar component. It is linked with ReactMeteorData that is defined in ReactMeteorDataWrap.jsx. After signing up, i get

Solution 1:

When you log in and you're redirected to /dashboard, two things happen at once:

  1. React renders the new components
  2. Meteor starts to synchronize the Meteor.users collection.

There's no guarantee that Meteor.user() is available by the time React starts rendering. In fact it's very probable that the user is still undefined when the React component mounts.

When your ReactMeteorDataWrap.render calls getMeteorData, the user still is undefined, that's what you see. The problem is that your code doesn't call getMeteorData again when the user document is updated.

There are several ways you can fix this. I'd recommend using createContainer form the react-meteor-data package, which is similar to your ReactMeteorDataWrap class, except that it actually works. :)

Here's a fix that makes this.props.user be available in NavBar:

exportdefaultcreateContainer(() => {
  return { user: Meteor.user() };
}, NavBar);

Post a Comment for "Currentuser Is Displayed Undefined"