-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e982cca
commit 1702950
Showing
4 changed files
with
39 additions
and
3 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,33 @@ | ||
import React, { Component } from 'react'; | ||
import { observer } from 'mobx-react' | ||
import DevTools from 'mobx-react-devtools'; | ||
import logo from './logo.svg'; | ||
import './App.css'; | ||
|
||
class App extends Component { | ||
render() { | ||
const {counter} = this.props; | ||
return ( | ||
<div className="App"> | ||
<div className="App-header"> | ||
<img src={logo} className="App-logo" alt="logo" /> | ||
<h2>Welcome to React</h2> | ||
<h2>Welcome to React + MobX</h2> | ||
</div> | ||
<p className="App-intro"> | ||
To get started, edit <code>src/App.js</code> and save to reload. | ||
</p> | ||
<p> | ||
Counter: | ||
<span className={counter.isOdd ? 'Counter-odd' : 'Counter-even'}> {counter.count} </span> | ||
</p> | ||
<p> | ||
<button onClick={() => counter.increment()}> + </button> | ||
<button onClick={() => counter.decrement()}> - </button> | ||
</p> | ||
<DevTools /> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default App; | ||
export default observer(App); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { extendObservable, computed } from 'mobx'; | ||
|
||
class Counter { | ||
constructor() { | ||
extendObservable(this, { | ||
count: 0, | ||
isOdd: computed(() => this.count % 2 === 1) | ||
}); | ||
} | ||
|
||
increment() { | ||
this.count++; | ||
} | ||
|
||
decrement() { | ||
this.count--; | ||
} | ||
} | ||
|
||
export default Counter; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import Counter from './Counter'; | ||
import App from './App'; | ||
import './index.css'; | ||
|
||
ReactDOM.render( | ||
<App />, | ||
<App counter={new Counter()} />, | ||
document.getElementById('root') | ||
); |