Canonical Way of Accessing Meteor.user() on client in React?

Meteor.user() isn’t available in render() in React. Do I really need a data container for this or what am I doing wrong?

I found this question which suggests using a separate package that has potential security issues and that isn’t plug and play.

So do I need a separate container just to access Meteor.user() in react? I need more than just Meteor.userId() FYI.

This is just for a cancel subscription page so should be a trivial thing that I check if the user is a paid sub or not. Also this is not a publish/profile problem because this data is published correctly.

in short: yes.

Most meteor data-sources are “Tracker-reactive”, that means that they can inform the caller that it should rerun when they have changed.

E.g. if you login, Meteor.user() changes from null to your user object.

vanilla-react however does not know this concept of reactivity, that’s why you need createContainer (or react-komposer’s composeWithTracker) to update the react-component.

1 Like