How it works...
This recipe leverages the NetInfo module to control when an AJAX request should be made.
In step 6, we defined the method that's executed when the Submit Data button is pressed. If there is no connectivity, we save the request body into the pendingSync class variable.
In step 3, we defined the componentWillMount life cycle hook. Here, two NetInfo method calls retrieve the current network connection status and attach an event listener to the change event.
In step 4, we defined the function that will be executed whenever the network connection has changed, which informs the state's isConnected Boolean property appropriately. If the device is connected, we also check to see whether there is a pending API call, and complete the ...
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