Tracker.autorun not re-running in componentWillMount()


#1

I have a query to a Mongo collection inside the componentWillMount function of a React component, like this:

componentWillMount() {
        Meteor.subscribe('SomePub');

        Tracker.autorun(() => {
            var data = SomeColl.find({}).fetch();
            console.log(data);
        });
}

but the Tracker.autorun function does not run when the data changes, hence data does change form being undefined. Any ideas?


#2

You subscribe ‘SomePug’, but you do the find in SomeColl. Have you subscribe it before?


#3

Use createContainer instead https://guide.meteor.com/react.html#using-createContainer


#4

Thanks for the suggestion, but I am hoping to avoid using createContainer in favour of a more React-centric method.