Meteor JS ReactMeteorData - CreateContainer - 超级表达式必须为null或函数

时间:2017-06-04 08:35:33

标签: javascript reactjs meteor meteor-react

从1.4升级到Meteor 1.5后,react-meteor-data的createContainer函数出现以下错误:

Uncaught TypeError: Super expression must either be null or a function, not undefined
    at exports.default (modules.js?hash=fb99b6a…:1144)
    at ReactMeteorData.jsx:6
    at ReactMeteorData.jsx:6
    at createContainer (createContainer.jsx:16)
    at AppContainer.jsx (AppContainer.jsx:8)

AppContainer.jsx:

import { Meteor } from 'meteor/meteor';

import { Session } from 'meteor/session';
import { createContainer } from 'meteor/react-meteor-data';

import App from '../layouts/App.jsx';

export default AppContainer = createContainer(props => {
  return {
    currentUser: Meteor.user(),
  };
}, App);

下面的App文件,在构造函数中我正在执行super(props)但是仍然会抛出错误

App.jsx:

class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      menuOpen: false,
      showConnectionIssue: false,
      headerTitle: null,
    };
    this.setHeaderTitle = this.setHeaderTitle.bind(this);
    this.logout = this.logout.bind(this);
  }

  logout() {
    Meteor.logout();
    this.context.router.replace(`/home`);
  }

  render() {
    ... omitted render function
  }
}

App.propTypes = {
  user: React.PropTypes.object,      // current meteor user
  connected: React.PropTypes.bool,   // server connection status
  loading: React.PropTypes.bool,     // subscription status
  menuOpen: React.PropTypes.bool,    // is side menu open?
  children: React.PropTypes.element, // matched child route component
  location: React.PropTypes.object,  // current router location
  params: React.PropTypes.object,    // parameters of the current route
};

App.contextTypes = {
  router: React.PropTypes.object,
};

export default App;

3 个答案:

答案 0 :(得分:1)

尝试以下代码段:

export default AppContainer = createContainer((props) => {
  // do subscriptions if you have any
  return {
    currentUser: Meteor.user(),
  };
}, App);

答案 1 :(得分:0)

个人而言,对于容器数据我喜欢这样(来自masterchef Base,更新并正常工作):

.data

希望它有用。

答案 2 :(得分:0)

您可能在App Component中缺少super()。 你能分享一下App Component的代码吗?