Thursday 22 June 2023

How to check Internet connectivity in React-Native code

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;
    }
}



And below is the code how to call CheckInternetConn function in yourscreen.js screen



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

Find Hours Diffrence in Kotlin

  In Kotlin, determining the difference in hours between two timestamps is a common task, especially in scenarios involving time-based calcu...