Skip to content

Instantly share code, notes, and snippets.

@vmaark
Last active April 21, 2020 20:15
Show Gist options
  • Select an option

  • Save vmaark/85f9e01f8520cf1a39977da0a531ba87 to your computer and use it in GitHub Desktop.

Select an option

Save vmaark/85f9e01f8520cf1a39977da0a531ba87 to your computer and use it in GitHub Desktop.
minimal MobX example
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