I wish to show a modal dialog box (such as an alert()
) every time a Meteor subscription, tracked in React with withTracker
, changes.
I have tried using Tracker.autorun
to track changes but cannot work out where in the code to place it. It does not seem to work in the Component
constructor and runs every time if placed in render()
.
This is an outline of what my code looks like:
class Foo extends Component {
render() {
return (
<h1>Example Header</h1>
{ this.maybeShowAlert() }
);
}
maybeShowAlert() {
// ONLY if bar has been updated
alert('bar has changed');
}
}
export default withTracker(() => {
Meteor.subscribe('bar')
return {
bar: Bar.findOne({})
};
})(Foo);