Last active
August 19, 2020 02:18
-
-
Save AKST/183151816549a2c75d3b758f657b3408 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 Controller { | |
@mobx.observable.ref count = 0; | |
@action | |
increment() { | |
this.count += 1; | |
} | |
} | |
// exposing a controller for a singleton component | |
function createCount() { | |
const countCtrl = new Controller(); | |
const Count = observer(() => ( | |
<div>Count {countCtrl.count}</div> | |
)); | |
return { Count, countCtrl }; | |
} | |
const { countCtrl, Count } = createCount(); | |
const appRoot = document.getElementById("root"); | |
ReactDOM.render(appRoot, <Count/>); | |
setTimeout(() => count.increment(), 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment