-
Notifications
You must be signed in to change notification settings - Fork 160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
withTracker with async code #393
Comments
Currently, the way to go for using the async tracker is what we have documented in the react-meteor-data docs, which uses the Suspense API. The following code was taken from the docs: import { useTracker } from 'meteor/react-meteor-data/suspense'
import { useSubscribe } from 'meteor/react-meteor-data/suspense'
function Tasks() { // this component will suspend
useSubscribe("tasks");
const { username } = useTracker("user", () => Meteor.user()) // Meteor.user() is async meteor 3.0
const tasksByUser = useTracker("tasksByUser", () =>
TasksCollection.find({username}, { sort: { createdAt: -1 } }).fetchAsync()) // async call
);
// render the tasks
} |
Thank you for the information, is there also a suspension implementation planned for withTracker ? |
Got! I have not talked about having a suspense version of |
OK thank you, by the way I made a minor adjustment and it seems to work fine. Unfortunately I don't know TS so it's in JS. import React, { forwardRef, memo } from 'react';
import { useTracker } from 'meteor/react-meteor-data/suspense';
export const withTracker = (options) => {
return (Component) => {
const getMeteorData = typeof options === 'function' ?
options :
options.getMeteorData;
const WithTracker = forwardRef((props, ref) => {
const data = useTracker('', () => getMeteorData(props) || {});
// const data = {};
return (
<Component ref={ref} {...props} {...data} />
);
});
const { pure = true } = options;
return pure ? memo(WithTracker) : WithTracker;
};
}; |
Hi developers,
I wanted to ask if it is possible to use the withTracker function call in combination with the asynchronous call that will be introduced in Meteor 3.0
I have a large application where I use the container architecture with React components
Example of container...
`import { withTracker } from 'meteor/react-meteor-data';
import {useDeps} from '@beisen/storybook-mantra-core';
import _ from 'lodash';
import locales from '../components/locales.jsx';
import {Locales} from '/lib/collections';
export const depsMapper = (context) => ({
context: () => context
});
const localesWT = withTracker(({context, id}) => {
const {Log, LocalState} = context();
let localesArray = Locales.find({language: 'en'}).fetch();
return {
localesArray
};
})(locales);
export default useDeps(depsMapper)(localesWT);
`
In the withTracker function I would like to call asynchronously however currently the content is rendered and does not wait for await...
Can we expect the withTracker function to be modified for use with Meteor.callAsync ?
Thanks
The text was updated successfully, but these errors were encountered: