Detect if the user is connected to the internet?

check if internet connection exists with javascript?
javascript detect slow internet connection
jquery check internet connection
check internet connection in reactjs
url to check internet connection
javascript check if url is reachable
jquery detect internet connection speed
javascript check if website is up

I'd like to route the user to a certain screen, in case he is not connected to the internet.

I just can't detect if he is connected or not.

I tried this code, but did not work:

async componentWillMount()
   if (!await NetInfo.isConnected)

Any tested solution to suggest?

Try await NetInfo.isConnected.fetch()

ref :

Detect the Internet connection is offline?, onLine property provides a Boolean value for whether or not the user is connected to the internet. You can access as such: if(navigator.onLine) { //  WiFi Thief Detector - Detect Who Use My WiFi can easily scan my wifi and see how many people or devices connected to your wifi router such as tplink/tp-link router, dlink router, netgear router or

You can check using NetInfo . for that you have to add connectionChange event listener like this

componentDidMount() {
        NetInfo.isConnected.addEventListener('connectionChange', this.handleConnectionChange.bind(this));
            (isConnected) => { this.setState({ isConnected: isConnected }); }

and then remove the event listener in componentWillUnmount

componentWillUnmount() {
        NetInfo.isConnected.removeEventListener('connectionChange', this.handleConnectionChange);

And finally the handler method for connection change. I am storing the status in device local storage you can do whatever you want.

handleConnectionChange = (isConnected) => {
        if (isConnected) {
            //'Data sync in process...', ToastAndroid.SHORT);
                .then((json) => JSON.parse(json))
                .then((data) => {
        else {'You are offline.', ToastAndroid.SHORT); }

        this.setState({ isConnected: isConnected });

Don't forget to add NetInfo from react-native :)

Detect Online Connection with JavaScript, In this post, we are going to look at a super-easy way to check if the user is connected to the internet and detect if they lose connection or  Here are a few ways to detect if someone is connected to your WiFi: Look out for poor speed. The more users on the network, the bigger the load. Unexpected and very sudden connection drops might mean someone is using brute methods in order to hack into your network.

Another solution to your case (one without using isConnected property) is to use the object returned from the event handler directly like that:

componentDidMount() {
  NetInfo.addEventListener('connectionChange', this.handleNetworkChange);

componentWillUnmount() {
  NetInfo.removeEventListener('connectionChange', this.handleNetworkChange);

handleNetworkChange = (info) => {
    if (info.type === 'none') {

According to NetInfo documentation:

connectionChange event fires when the network status changes. The argument to the event handler is an object with keys:

type: A ConnectionType (listed above)

effectiveType: An EffectiveConnectionType (listed above)

The connection type can be one of the following : none, wifi, cellular, unknown.

Ideally you can store this information to your redux store and the listener to a root component.

We had a weird bug when using isConnected similar to the one you mentioned @Gabriel Bleu but for us, the NetInfo.isConnected.fetch() returned false only when the Android device was awake after some period of inactivity.We used it to display offline warning for users, so the warning never left. I found this solution on a Spencer Carli's course and it seems to work better but depending on your needs, you might want to use isConnected combined with the above code.

Detecting If a User is Online/Offline with JavaScript - DEV, You can use the ConnectivityManager to check that you're connected to the internet, and if you are, to determine what type of connection is in place. Checking the Internet. The next step is to see what's what with your Internet connection. I could tell you a lot of fancy things to try, but I'll make this really simple.

This is a great example to check online or offline and even you can have connection change information too. Source

NetInfo.isConnected.fetch().then(isConnected => {
  console.log('First, is ' + (isConnected ? 'online' : 'offline'));
function handleFirstConnectivityChange(isConnected) {
  console.log('Then, is ' + (isConnected ? 'online' : 'offline'));

Monitor connectivity status and connection metering, Check a device's network connection; Manage network usage; Implement If a network connection is unavailable, your application should respond gracefully. interfaces is connected (meaning that an internet connection is not available): When your app has a settings activity that allows users to control  There is absolutely no way you can reliably check if there is an internet connection or not (I assume you mean access to the internet). You can, however, request resources that are virtually never offline, like pinging or something similar. I think this would be efficient.

Manage network usage, We can detect if the user is online or offline by using the online will return true if the user is connected to the internet, otherwise it returns false… If the user was doing work locally without a connection, for example, the web app could detect that and save all changes within localStorage until the user connected to the internet and then the app could send data to the server.

Detecting Online/Offline Status in Javascript, When your app has strict dependency to internet… the operations and take proper actions i.e. let user know about connection status change, So how can we check if the internet is available and connected in the device? InternetCheckConnection can be called to determine if a connection to a specific destination can be established. A return value of TRUE indicates that either the modem connection is active, or a LAN connection is active and a proxy is properly configured for the LAN. A return value of FALSE indicates that neither the modem nor the LAN is connected.

Android Reachability, I'm not talking about detection if user is connected to some network (WIFI checking if a device is connected to the internet, this method bellow. If you believe that someone is connected to your WiFi and using the internet without your permission, then you should give Who Use My WiFi – Network Scanner a try. The Android app scans all WiFi network devices in seconds. Not only that, but Who Use My WiFi – Network Scanner also has a Ping tool, Port scanner, network monitor, etc. 12.