Mobx cannot get the static property of class when using it.

topic description

this.props.name is not displayed, but the event triggered by onclick is valid, which changes the value of name to "ls"

. < H1 > written as class class cannot be fetched < / H1 >

import {observable,action,computed} from "mobx"
class TodoList {
    @observable name = "hi"
    @action change(){
        console.log("change")
        this.name = "ls"
    }
}

export default new TodoList()
< H1 > problem: P tag cannot get a value < / H1 >


@observer
class App extends React.Component {

  render() {
    return (
        

{this.props.todoList.name}

// ) } } export default App;
< H1 > but if TodoList writes like this, the p tag can take the value < / H1 >
export default new TodoList("zs")

let TodoList = observable({
    name :"hi",
    change(){
        this.name = "ls"
    }
})

export default TodoList

finally solved, add plugins configuration (using the project created by create-react-app) to package.json

"babel": {
    "presets": [
      "react-app"
    ],
    "plugins": [// 
      "babel-plugin-transform-decorators-legacy"// 
    ]
  },

el ": {

"presets": [
  "react-app"
],
"plugins": [// 
  "babel-plugin-transform-decorators-legacy"// 
]

1. First exclude whether decorator is effective
2. If it works, you need to pass in todoList as an attribute

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e8a21f-fb0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e8a21f-fb0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?