Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor() {
super();
this.online = true;
NativeNetInfo.getConnectionInfo().then(connectionState => {
this.online = hasOnlineConnectionState(connectionState);
});
NativeNetInfo.addEventListener('connectionChange', (connectionState)=>{
var isNowOnline = hasOnlineConnectionState(connectionState);
// React Native counts the switch from Wi-Fi to Cellular
// as a state change. Return if current and previous states
// are both online/offline
if (this.online === isNowOnline) return;
this.online = isNowOnline;
if (this.online){
this.emit("online");
} else {
this.emit("offline");
}
});
}