ReactJS .default 不是构造函数
ReactJS .default is not a constructor
我是 React 和 Mobx 的新手,所以我尝试做一个小应用程序。当我尝试 运行 时,出现错误:Uncaught TypeError: _releasesState2.default is not a constructor
。我正要 bash 我的头,因为我不知道问题是什么。这是我到目前为止得到的:
我的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>
)
}
}
和发布-state.js:
import { observable } from "mobx"
class ReleaseState {
@observable releases = [];
constructor() {
let data = [] // some array with data
}
}
const releaseState = new ReleaseState();
谁能告诉我这里出了什么问题?
您似乎忘记导出 ReleaseState
?
export default releaseState;
您没有在 release-state.js
中导出 ReleaseState
class。尝试将您的代码修改为:
export default class ReleaseState {
...
我是 React 和 Mobx 的新手,所以我尝试做一个小应用程序。当我尝试 运行 时,出现错误:Uncaught TypeError: _releasesState2.default is not a constructor
。我正要 bash 我的头,因为我不知道问题是什么。这是我到目前为止得到的:
我的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>
)
}
}
和发布-state.js:
import { observable } from "mobx"
class ReleaseState {
@observable releases = [];
constructor() {
let data = [] // some array with data
}
}
const releaseState = new ReleaseState();
谁能告诉我这里出了什么问题?
您似乎忘记导出 ReleaseState
?
export default releaseState;
您没有在 release-state.js
中导出 ReleaseState
class。尝试将您的代码修改为:
export default class ReleaseState {
...