Skip to content

Instantly share code, notes, and snippets.

@abdyer
Last active November 30, 2017 09:06
Show Gist options
  • Save abdyer/8b29026440b1f6c06e3d2f7bc149fbe8 to your computer and use it in GitHub Desktop.
Save abdyer/8b29026440b1f6c06e3d2f7bc149fbe8 to your computer and use it in GitHub Desktop.
class BeerList extends React.Component {
componentDidMount() {
this.changeListener =
DeviceEventEmitter.addListener(
'beersChanged',
this.onBeersChanged);
NativeModules.BeerLiveData.subscribe();
}
componentWillUnmount() {
this.changeListener.remove();
NativeModules.BeerLiveData.unsubscribe();
}
beersChanged = (event) => {
const beers = JSON.parse(event.beers);
this.setState({beers: beers});
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment