How to stop Tracker when component UnMount?


#1

Suppose I have:

tracking() {
  Tracker.autorun(() => {
    if (someMeteorReactiveVariable()) {
      // do something
    };
  });
}

How do I stop above tracker when component unmount?

I’m asking to stop tracker because Tracker will always rerun even though component has already unmounted and creating unnecessary warning.


#2
tracking() {
  this.computation = Tracker.autorun(() => {
    if (someMeteorReactiveVariable()) {
      // do something
    };
  });
}

componentWillUnmount() {
  this.computation.stop();
}

Alternatively, you can use createContainer or getMeteorData, which stop things for you when the component unmounts.


#3

Prefect! Thanks @sashko