-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
I did something like below..
import React, { Component } from 'react';
import { Alert } from 'react-native';
import { hasInternetConnection } from 'react-native-connection-status';
import SwitchNavigator from './navigator/AppNavigator';
export default class App extends Component<> {
constructor() {
super();
this.state = {
connectionStatus: 'Internet connection available.'
};
}
componentDidMount() {
this.checkConnection();
}
//Checking Internet Connectivity
checkConnection = () => {
hasInternetConnection((isConnected: boolean) => {
console.log(isConnected);
if (!isConnected) {
Alert.alert(
'Unexpected error',
'Not connected to internet',
[
{ text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel' },
{ text: 'OK', onPress: () => console.log('OK Pressed') }
],
{ cancelable: false }
);
this.setState({
connectionStatus: 'Internet connection not available.'
});
}
console.log(this.state.connectionStatus);
});
};
render() {
return <SwitchNavigator />;
}
}
It checks for internet only once.. i want it to listen to change in connectivity. How do i do that?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels