Created
February 27, 2017 18:38
-
-
Save drewhamlett/7c2749408b5b92436ec1f7470c4e1c56 to your computer and use it in GitHub Desktop.
Object not updating component
This file contains 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
// 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> | |
) | |
} | |
} | |
This file contains 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
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