Created
October 27, 2017 19:33
-
-
Save melikhov-dev/75ec57287c8c70ec53c9553096da865a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Определяем состояние и методы для его обновления | |
class MobxState { | |
@observable items = [] | |
addItem (item) { | |
this.items.push(item) | |
} | |
} | |
// Компоненты | |
@observer | |
class Items extends Component { | |
render() { | |
return ( | |
<div> | |
<ul> | |
{this.props.store.items.map((item) => <li>{item}</li>)} | |
</ul> | |
<button onClick={() => this.props.store.addItem('foo')}> | |
Add foo | |
</button> | |
</div> | |
) | |
} | |
} | |
// Передаём состояние в компоненты | |
const store = new MobxState(); | |
render(<Items store={store} />, document.getElementById('mount')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment