I have a question about useTracker, guess this is a basic question but I really don’t know the answer. Which option is better performing? (Assuming that there’s already a top level sub ready publishing data from Coll1 and Coll2)
It would be more of a difference if you would be able to have both find’s in separate components. That would make a difference but whether possible depends on the data / component of course.
If the data from Coll1 and Coll2 is relatively small and doesn't change frequently, using useTracker directly in the component might be a simple and efficient approach. On the other hand, if the data in Coll1 and Coll2 is extensive or frequently updated, it might be better to use a top-level subscription.
Direct answer: When you have a useTracker, you’ll always want to add a deps array. Otherwise the Tracker will be destroyed and a new one will be created for each rerender, which is bad! For example, if you have no deps, pass an empty array:
Next, it’s true that using separate trackers can use less cpu cycles, but in the land of react rerenders are your enemy, not local data fetching-- I’ve never once seen anyone bother with it. Producing nice and readable code is generally preferred as the differences, especially in example code like yours is negligible.
Lastly, I should point out that the DDP implementation on the meteorrn package differs from the official implementation. I wound up copying the official meteor client into my react native project, which wound up being a great investment. It’s a difficult process, but I have posted my learnings here: Official meteor client in react native