Http://cn.mobx.js.org/refguide/observer-component.html
Observable Local component states
Like ordinary classes, you can introduce observable properties on the react component by using the @observable adorner. This means that you can have equally powerful local states in your components, without the need to manage them through react's lengthy and mandatory setstate mechanisms. The response state is invoked by render, but no other react lifecycle method is invoked, except for Componentwillupdate and Componentdidupdate. If you need to use other react lifecycle methods, simply use the general react API based on the state.
The above example can also be written like this:
Import {Observer} from "Mobx-react"
Import {observable} from ' Mobx '
@observer class Timer extends React.component {
@observable secondspassed = 0
componentwillmount () {
setinterval (() => {
this.secondspassed++
}, 1000)
}
render () {
Return (<span>seconds passed: {this.secondspassed} </span>)
}
Reactdom.render (< Timer/>, document.body)
Copy
For a more advantageous use of observable local component state, see why I no longer use the SetState three reasons.