Consider the following code:
defaultPage = new ReactiveVar();
function App() {
[page, setPage] = useState();
useEffect(() => {
console.log(Tracker.currentComputation);
const observer = Objects.find({page: page}).observe({added: ...});
return () => observer.stop();
}, [page]);
useTracker(() => {
if (!page) {
setPage(defaultPage.get());
}
}, [!page]);
...
}
I find that the useEffect callback is run within a Tracker (the console.log outputs an actual computation), presumably triggered by setPage called within useTracker. I tried wrapping setPage within Tracker.nonreactive, but the effect callback is still called reactively. This seems wrong...
The result of this is pretty annoying. The tracker actually gets called twice, and because of the if, only the first one triggers the observer to be created. Because the observer was created within a tracker, the second call of the tracker invalidates the first call so the observer gets destroyed and not recreated. 🙁
I tested in react-meteor-data 2.1.4, 2.2.1, and 2.2.2 (wondering whether the recent rewrite had an effect) and both have the same issue. I'm using React 17.0.1
Consider the following code:
I find that the
useEffectcallback is run within a Tracker (theconsole.logoutputs an actual computation), presumably triggered bysetPagecalled withinuseTracker. I tried wrappingsetPagewithinTracker.nonreactive, but the effect callback is still called reactively. This seems wrong...The result of this is pretty annoying. The tracker actually gets called twice, and because of the
if, only the first one triggers the observer to be created. Because the observer was created within a tracker, the second call of the tracker invalidates the first call so the observer gets destroyed and not recreated. 🙁I tested in
react-meteor-data2.1.4, 2.2.1, and 2.2.2 (wondering whether the recent rewrite had an effect) and both have the same issue. I'm using React 17.0.1