我正在尝试使用decorate
中的mobx-react
制作可观察的属性但是,我收到错误:
Uncaught TypeError: Object(...) is not a function
at Object../src/vrp-ui/Button.js (Button.js:32)
at __webpack_require__ (bootstrap 8330eff5292135af9e26:19)
at Object../src/map/StudentsMap.js (logo.svg:1)
at __webpack_require__ (bootstrap 8330eff5292135af9e26:19)
at Object../src/App.js (App.css?9a66:26)
at __webpack_require__ (bootstrap 8330eff5292135af9e26:19)
at Object../src/index.js (index.css?f255:26)
at __webpack_require__ (bootstrap 8330eff5292135af9e26:19)
at Object.0 (Button.js:32)
at __webpack_require__ (bootstrap 8330eff5292135af9e26:19)
这是我的实施:
import React, { Component } from 'react'
import {Button} from 'semantic-ui-react'
import axios from 'axios'
import { decorate, observable } from "mobx"
class componentName extends Component {
//@observable vrp_solution = {};
constructor () {
super()
this.state = {
solution: []
}
this.handleClick = this.handleClick.bind(this)
}
handleClick () {
axios.post('http://localhost:8000/vrp/')
.then(response => {
vrp_solution= "!";
console.log(response)})
}
render() {
return (
<Button onClick={this.handleClick}>
Calculate Best Routes!
</Button>
)
}
}
export default decorate(componentName,{vrp_solution: observable });
#Error is here:
export default decorate(componentName,{vrp_solution: observable });
如果我删除decorate
错误消失了..
任何想法?
答案 0 :(得分:0)
装饰和观察来自mobx而不是mobx-react, 尝试,
从“mobx”导入{decorate,observable}
你的按钮也应该是
<Button>
Calculate Best Routes!
</Button>