使用装饰时对象(...)不是函数

Object(...) is not a function when using decorate

我试图通过使用 mobx-react 中的 decorate 来使 属性 可观察,但是,我收到错误消息:

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 错误就会消失.. 有什么想法吗?

decorate 和 observable 来自 mobx 而不是 mobx-react, 试试,

import { decorate, observable } from "mobx"

你的按钮也应该是

<Button>
   Calculate Best Routes!
</Button>