How to stop/invalidate certain Tracker for rerunning?


#1

I have Tracker.autorun like so:

Tracker.autorun(() => {
  if (Meteor.user()) {
    // do something
  };
});

I’m using above function for watching login state of current user and do something if current user is logged in. How do I flush/invalidate above tracker when do something is already execute so that above tracker won’t rerun?

Thanks


#2

Tracker.autorun returns a handle with a stop method which you can use.

    let handle = Tracker.autorun(() => {
        if (Meteor.user()) {
           handle.stop();
        };
    });