How to do it...

  1. Let's start by importing the necessary dependencies into App.js:
import React, { Component } from 'react';import {  SafeAreaView,  NetInfo,  StyleSheet,  Text,  View,  Platform} from 'react-native';
  1. Next, we'll define the App class and a state object for storing the connectivity status. The online Boolean will be true if connected, and the offline Boolean will be true if it isn't:
export default class App extends Component {  state = {    online: null,    offline: null,  };  // Defined in later steps}
  1. After the component has been created, we need to get the initial network status. We are going to use the NetInfo class's getConnectionInfo method to get the current status, and we'll also set up a callback that's going to be executed ...

Get React Native Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.