https://github.com/suhdev/mobx-observer-hook
https://github.com/suhdev/mobx-observer-hook
Last synced: 9 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/suhdev/mobx-observer-hook
- Owner: suhdev
- Created: 2019-07-07T15:19:50.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-07-07T16:15:53.000Z (almost 7 years ago)
- Last Synced: 2025-09-13T14:22:09.924Z (10 months ago)
- Language: JavaScript
- Size: 3.91 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# mobx-observer-hook
## Usage
```typescript
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { observable, action } from 'mobx';
import { useObserver } from 'mobx-observer-hook';
class Model {
@observable name = 'test';
@observable time:Date = new Date();
@action.bound
setTime(time:Date) {
this.time = time;
}
}
function MyComponent({model}) {
return useObserver(()=>
{model.name} - {model.time.toString()},[model]);
}
let el = document.getElementById('app');
if (!el){
el = document.createElement('div');
el.id = 'app';
document.body.appendChild(el);
}
const m = new Model();
m.name = 'Suhail';
ReactDOM.render(
,
el
);
setInterval(()=>{
m.setTime(new Date());
},1000);
```