withTracker 和 async 看起来很奇怪
export const PageLayoutContainer = withTracker(({}) => {
const logContext = "PageLayoutContainer";
// console.log(logContext, "subscribe('translations')")
let subscriptionTranslations = Meteor.subscribe('translations');
let user ;
// user = await Meteor.userAsync();
let result = {
subscriptionReady: subscriptionTranslations.ready(),
user: user
};
return result;
})(PageLayout)
-> 我们没有用户,因为它是在异步方法中,但更新被传递到 PageLayout 并且 subscriptionReady 在某个时刻变为 true。
我在 withTracker 中切换到异步方法来获取用户,结果没有更新(subscriptionReady 从未改变),但我们有了用户
export const PageLayoutContainer = withTracker(async ({}) => {
const logContext = "PageLayoutContainer";
// console.log(logContext, "subscribe('translations')")
let subscriptionTranslations = Meteor.subscribe('translations');
let user ;
user = await Meteor.userAsync();
let result = {
subscriptionReady: subscriptionTranslations.ready(),
user: user
};
return result;
})(PageLayout)
我错过了什么吗?
到目前为止,我正在将组件( PageLayout )中的所有异步内容移至 useEffect 中...