在Meteor / React中从createContainer迁移到withTracker

时间:2018-07-06 18:06:35

标签: reactjs meteor

流星/ React newb在这里,我在以下情况下从createContainer(已贬值)升级到withTracker时遇到了问题。

export default createContainer(() => {
  Meteor.subscribe('users', PER_PAGE);

  return { users: Users.find({}).fetch() };
}, UsersList);

我尝试了以下方法...

import { withTracker } from 'meteor/react-meteor-data';

.....

export default withTracker(() => {
  Meteor.subscribe('users', PER_PAGE);

  return { users: Users.find({}).fetch() };
}, UsersList);

但是控制台出现错误:

Warning: Functions are not valid as a React child. This may happen if you return a Component instead of <Component /> from render. Or maybe you meant to call this function rather than return it.

有人可以告诉我我要去哪里了吗?

1 个答案:

答案 0 :(得分:0)

这似乎是代码段最后一行中的语法错误

export default withTracker(() => {
  Meteor.subscribe('users', PER_PAGE);

  return { users: Users.find({}).fetch() };
}, UsersList); 

替换
export default withTracker(() => {
  Meteor.subscribe('users', PER_PAGE);

  return { users: Users.find({}).fetch() };
})(UsersList);