Skip to content

Instantly share code, notes, and snippets.

@peterkle
Last active September 1, 2017 22:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterkle/fe7b2dc080a8c6dcb6e7720a9efa8408 to your computer and use it in GitHub Desktop.
Save peterkle/fe7b2dc080a8c6dcb6e7720a9efa8408 to your computer and use it in GitHub Desktop.
Example of MobX and React
// MobX store
class GuestCollection extends Collection {
@observable guestList;
initCollection() {
XoApi.fetch(GuestCollection.apiUrl)
.then(GuestCollection.processGuestList)
.then(GuestCollection.updateGuestList)
// …
}
}
// React component
@inject('guestCollection')
@observer
class GuestList extends Component {
render() {
return (
<div>
{
this.props.guestCollection.map(guest =>
<Row guest={guest} key={guest.id} />
)
}
</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment