Last active
September 25, 2024 06:51
-
-
Save mastermoo/740f5e83c60f32ea366595ec0a88ecdc to your computer and use it in GitHub Desktop.
counter example using mobx
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
// store.js | |
import {observable} from 'mobx'; | |
class CounterStore { | |
@observable counter = 0; | |
increment() { this.counter++; } | |
decrement() { this.counter--; } | |
} | |
export default new CounterStore(); | |
// MyComponent.js | |
import React from 'react'; | |
import {observer} from 'mobx-react'; | |
import store from './store.js'; | |
const Counter = () => ( | |
<div> | |
<button onClick={() => store.increment()}>+1</button> | |
<span>{store.counter}</span> | |
<button onClick={() => store.decrement()}>-1</button> | |
</div> | |
); | |
export default observer(Counter); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why there is no
accessor
keyword?Documentation says: