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