Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In React Native Android How to check internet connection is online /offline in application background? [closed]

I need to check Internet Connection while Application Background

like image 220
Saravana Kumar Avatar asked Mar 24 '17 05:03

Saravana Kumar


People also ask

How do you handle offline in React Native?

The most popular methods to achieve offline support in React Native are by implementing usage restrictions, caching, and request queuing.

Can React Native app run without internet?

You'll need internet connection to install the React Native CLI and create your app (this will fetch React Native and its JavaScript dependencies). You'll also need internet connection the first time you run react-native run-android because this will download third-party Android dependencies.


1 Answers

import { NetInfo } from 'react-native';

NetInfo.isConnected.fetch().then(isConnected => {
           if(isConnected)
           {
               console.log('Internet is connected');
           }
})

This above code is sufficient to check if there is active net connection or not

like image 125
krishnazden Avatar answered Oct 10 '22 18:10

krishnazden