Last active
April 21, 2020 20:15
-
-
Save vmaark/85f9e01f8520cf1a39977da0a531ba87 to your computer and use it in GitHub Desktop.
minimal MobX example
This file contains hidden or 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
| import { observable } from 'mobx' | |
| import { Observer, useObserver, observer } from 'mobx-react' // 6.x or [email protected] | |
| import ReactDOM from 'react-dom' | |
| const person = observable({ | |
| name: 'John', | |
| }) | |
| const P3 = ({ person }) => { | |
| return useObserver(() => <h1>{person.name}</h1>) | |
| } | |
| ReactDOM.render( | |
| <div> | |
| <P3 person={person} /> | |
| </div>, | |
| ) | |
| setTimeout(() => { | |
| person.name = 'Jane' | |
| }, 1000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment