Skip to content

Instantly share code, notes, and snippets.

@AKST
Last active August 19, 2020 02:18
Show Gist options
  • Save AKST/183151816549a2c75d3b758f657b3408 to your computer and use it in GitHub Desktop.
Save AKST/183151816549a2c75d3b758f657b3408 to your computer and use it in GitHub Desktop.
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