When using a mobile app, network connectivity is something that is often taken for granted. But what happens when your app needs to make an API call, and the user has just lost connectivity? Fortunately for us, React Native has a module that reacts to the network connectivity status. We can architect our application in a way that supports the loss of connectivity by synchronizing our data automatically as soon as the network connection is restored.
This recipe will show a simple implementation of using the NetInfo module to control whether or not our application will make an API call. If connectivity is lost, we will keep a reference of the pending request and complete it when the network access is restored. We will be using http://jsonplaceholder.typicode.com again to make a POST request to a live server.