I am in the process of migrating my app to use findOneAsync etc. and I cannot find a reference on how to handle client calls within useTracker. It seems useTracker does not handle promised computations. Is this going to be part of Meteor 2.11?
Also it seems applyAsync is private in @types/meteor?! Can we safely use that one?
Hello @superfail, regarding types, we have been moving our types to the core: Using Core Types | Meteor API Docs I will check on that, but you can use applyAsync but note that it returns a Promise
Yes I am already using useFind where it makes sense. Here I am talking about cases where only Collection#findOneAsync makes sense. Is there a way to make findOneAsync work with useTracker today? Is it just an oversight in @types/meteor that promises are not allowed (they seem to be allowed in Tracker.autorun)?
Thanks, I will look into zodern:types. Why does it look like it still requires @types/meteor?
About applyAsync, does it really return a promise? From the docs and @types/meteor, it seems it accepts an “asyncCallback”.
I guess one could abuse useFind by limiting to the first result. What about Meteor.user(), Meteor.status() etc.? Are those going to remain synchronous?
This requires having a synchronous implementation of findOne to avoid invalid transient states. As hinted at here react-packages/useFind.ts at d0645787dac675bbf5412cac0da9387b6315f5c4 · meteor/react-packages · GitHub one can rely on the synchronous behavior of Cursor#observe on initialization to implement fetchSync and findOneSync. But is this the only way? Is this recommended? Should we use different patterns? Will Meteor provide a fetchSync and findOneSync function to ease the transition?
Is there any Documentation out now how to handle useTracker Async, e.g.
const Component = () => {
const user = useTracker(async () => Meteor.userAsync()) // will return a Promise we have to await!
// If we "await"/use async, then the Component gets async, which does not work!
}
I link here useTracker + React Suspense:
But I don’t get it. Doesn’t useTracker return a promise in the examples, we need to await?
EDIT: React Suspense Use Tracker can resolve a promise, it seems, we can work with this pattern.