ReactJS .default不是构造函数

时间:2017-09-12 21:28:17

标签: javascript reactjs mobx

我是React和Mobx的新手,所以我尝试做一个小应用。当我尝试运行它时,我收到错误:Uncaught TypeError: _releasesState2.default is not a constructor。因为我不知道问题是什么,所以我要打击我的脑袋。这是我到目前为止所得到的:

我的index.js:

import React from "react";
import ReactDOM from "react-dom";

import Releases from "./components/releases";

class App extends React.Component {
  constructor() {
    super();
  } 
  render() {
    return (
        <div>
           <Releases />
        </div>
     )
  }
}

ReactDOM.render(<App/>, window.document.getElementById("app"));

releases.js:

import React from "react";
import { observer } from "mobx-react";

import ReleaseState from "./releases-state";

@observer
export default class Releases extends React.Component {
   constructor() {
     super();

    this.state = new ReleaseState();
   }
   render() {
     return (
        <div>
            // content here
        </div>
      ) 
   }
}

和releases-state.js:

import { observable } from "mobx"

class ReleaseState {
   @observable releases = [];

   constructor() {
      let data = [] // some array with data
   }
}

const releaseState = new ReleaseState();

有人可以告诉我这里有什么不对吗?

2 个答案:

答案 0 :(得分:3)

您没有导出ReleaseState中的release-state.js课程。尝试将代码修改为:

export default class ReleaseState {
  ...

答案 1 :(得分:0)

您可能忘记导出ReleaseState

export default releaseState;