How To Get Notify When No Connection In React Native

We always wanted to know when we lost internet connection instead of trying to figure out what’s wrong with the app or phone. So today I will show you how to get notify by react native when you do not have internet connection.

First Step

After you create your React Native Expo app, it will be time to install a library called NetInfo which will allows you to get information about connection type and connection quality.

Im using expo, to Install run this code

expo install @react-native-community/netinfo

After we install it, is time to import the library in the main file of your app by using this snippet

import NetInfo from '@react-native-community/netinfo'

Second Step

We imported our library in main file is time to check our connection, to do so we will use useEffect check our connection the moment we open our app.

We are fetching data from NetInfo of our application and we set result in variable to be use for rendering the message

Third step

Now is time to make a condition check when we lost internet connection

The result will be like this anytime we lost connection

--

--