In this blog we will see Internet connectivity is on or off in react-native code.
So below is the code to check is internet connected or not ?
import NetInfo from "@react-native-community/netinfo";export const CheckInternetConn = async () => {
try {
let ObjectNetwork = await NetInfo.fetch();
return ObjectNetwork.isConnected;
} catch (e) {
return false;
}
}
CheckInternetConn().then(function (response) {
if (response == false) {
Alert.alert("There is No Internet Available")
} else {
"Your code stuff here"
}
}
No comments:
Post a Comment
Comments