Skip to content

Instantly share code, notes, and snippets.

@williamtran29
Forked from knowbody/App.js
Created June 29, 2017 12:17
Show Gist options
  • Save williamtran29/4c2f8e9647b831f9f89bb95e71b075f6 to your computer and use it in GitHub Desktop.
Save williamtran29/4c2f8e9647b831f9f89bb95e71b075f6 to your computer and use it in GitHub Desktop.
Check internet connection in React Native app
// quick snippet to check the connection in your RN app
// dispatches an `setIsConnected` action every time the NetInfo changes (on/off network)
componentDidMount() {
const dispatchConnected = isConnected => this.props.dispatch(setIsConnected(isConnected));
NetInfo.isConnected.fetch().then().done(() => {
NetInfo.isConnected.addEventListener('change', dispatchConnected);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment