3
我想将mobx
与react
合并。由于我使用create-react-app
衍生出我的应用程序,因此我无法使用mobx提供的装饰器。reactjs mobx没有修饰器无法正常工作
既然我们可以用mobx无装饰按本文件:https://mobxjs.github.io/mobx/best/decorators.html
下面是我创建了一个组件:
import React, { Component } from 'react';
import observer from 'mobx-react';
export const TestComponent = observer(class TestComponent extends Component {
render() {
return <div>Just a test component!</div>
}
});
这里的上述部件的简单通话:
import React, { Component } from 'react';
import './App.css';
import Auth from './Auth'
import { TestComponent } from './Test'
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
import AppBar from 'material-ui/AppBar';
import authStore from './stores/Store'
class App extends Component {
constructor(props) {
super(props);
this.state = {
}
}
render() {
return (
<div className="app">
<MuiThemeProvider>
<div>
<TestComponent store={authStore} />
</div>
</MuiThemeProvider>
</div>
);
}
}
export default App;
现在,当我运行上面的组件,我得到错误:Uncaught TypeError: (0 , _mobxReact2.default) is not a function(…)
没有得到控制台中的显示。
我在这里做错了什么?
谢谢。我错过了这个基本的东西。 在附注上,我可以使用自定义反应脚本与我已经在工作的项目吗?我不想创建一个新的。 – Jazib
afaik是的,这是可能的 – mweststrate
你能给我一个指针,我怎么能做到这一点? – Jazib