Is it possible to use ready() inside of a useTracker
I’m using meteor/react-meteor-data
i want to do
const { someData } => useTracker(() => { const sub = Meteor.subscribe(publicMethod); if (sub.ready()) { do something here } return { someData, } },[]);
Yes, you can do this:
const { someData, loading } => useTracker(() => {
const sub = Meteor.subscribe('somePublication');
return {
someData: SomeCollection.find({}).fetch(),
loading: !sub.ready(),
}
}, [])
const sub = Meteor.subscribe('somePublication');
if (sub.ready()) {
// do something here
}
is this also possible? because at one point data is not ready yet and i get undefined but i need to do something specific right after its ready only inside of the useTracker itself
Yes. You can.
// I prefer to put that action in an useEffect.
Is there a reason you don’t use useSubscribe?