Last active
September 1, 2017 22:13
-
-
Save peterkle/fe7b2dc080a8c6dcb6e7720a9efa8408 to your computer and use it in GitHub Desktop.
Example of MobX and React
This file contains hidden or 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
// 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