How to stop Tracker when component UnMount?

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.

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.

2 Likes

Prefect! Thanks @sashko

1 Like