Skip to content

Instantly share code, notes, and snippets.

@drewhamlett
Created February 27, 2017 18:38
Show Gist options
  • Save drewhamlett/7c2749408b5b92436ec1f7470c4e1c56 to your computer and use it in GitHub Desktop.
Save drewhamlett/7c2749408b5b92436ec1f7470c4e1c56 to your computer and use it in GitHub Desktop.
Object not updating component
// Doesnt work
@inject('store')
@observer
class SelectUser extends Component {
onChange = (value) => {
this.props.store.user.update(value)
}
render() {
return (
<Select.Async
value={this.props.store.user}
valueKey="id"
labelKey="email"
onChange={this.onChange}
loadOptions={this.fetchUsers}
/>
)
}
}
// Works!
@inject('store')
@observer
class SelectUser extends Component {
onChange = (value) => {
this.props.store.user.update(value)
}
render() {
return (
<div>
{this.props.store.user.name}
<Select.Async
value={this.props.store.user}
valueKey="id"
labelKey="email"
onChange={this.onChange}
loadOptions={this.fetchUsers}
/>
</div>
)
}
}
class User {
@observable id = ''
@observable name = ''
@observable email = ''
@action update(value) {
this.id = value.id
this.name = value.name
}
}
const user = new User()
class Store {
@observerable user = user
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment