Created
February 9, 2017 02:05
-
-
Save ariesmcrae/02a3c1696612fe2bde592777fe28a5a6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>React Counter</title> | |
</head> | |
<body> | |
<br/><br/> | |
<div id="app"></div> | |
<script src="https://cdn.jsdelivr.net/g/[email protected](react.min.js+react-dom.min.js),[email protected]"></script> | |
<script src="https://unpkg.com/[email protected]/lib/mobx.umd.min.js"></script> | |
<script src="https://unpkg.com/[email protected]/index.js"></script> | |
<script src="https://npmcdn.com/mobx-react-devtools"></script> | |
</body> | |
</html> | |
const {observable} = mobx; | |
const {observer} = mobxReact; | |
const {Component} = React; | |
const Devtools = mobxDevtools.default; | |
const appState = observable({ | |
count: 0 | |
}); | |
appState.increment = function() { | |
this.count++; | |
} | |
appState.decrement = function() { | |
this.count--; | |
} | |
@observer class Counter extends Component { | |
render() { | |
return ( | |
<div> | |
<Devtools/> | |
Counter: {appState.count} <br/> | |
<button onClick={this.handleInc}> + </button> | |
<button onClick={this.handleDec}> - </button> | |
</div> | |
); | |
} | |
handleInc = () => { | |
appState.increment(); | |
} | |
handleDec = () => { | |
appState.decrement(); | |
} | |
} | |
ReactDOM.render( | |
<Counter store={appState} />, | |
document.getElementById('app') | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment