Skip to content

Instantly share code, notes, and snippets.

@git-toni
Last active November 19, 2016 17:04
Show Gist options
  • Save git-toni/342f747b1d120cfc87b9db88d1d2c3c0 to your computer and use it in GitHub Desktop.
Save git-toni/342f747b1d120cfc87b9db88d1d2c3c0 to your computer and use it in GitHub Desktop.
Mobx-React Provider test
import React,{Component} from 'react'
import ReactDOM from 'react-dom'
import {observable} from 'mobx'
import {observer, Provider} from 'mobx-react';
const store=observable({
num:33,
name:'john'
})
@observer // ALthough @observer(['store']) *does* work!
class MyComponent extends Component{
render(){
console.log('rendering', this.props)//< --- shouldnt it print the whole store observed object?ie { num:33, name:'john'}
return <h2>{this.props.store.toString()}</h2>
}
}
ReactDOM.render(
<Provider store={store}>
<MyComponent />
</Provider>,
document.getElementById("app-container")
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment