How it works...
In step 2, we created the initial state object with two properties: online will be true when a network connection is available, and offline will be true when it's not available.
In step 3, we retrieved the initial network status and set up a listener to check when the status changes. The network type returned by NetInfo will be either wifi, cellular, unknown, or none. Android also has the extra options of bluetooth, ethernet, and WiMAX (for WiMAX connections). You can read the documentation to see all of the available values: https://facebook.github.io/react-native/docs/netinfo.html.
In step 5, we defined the method that will execute whenever the network status changes, and set the state values of online and offline accordingly. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access