How to handle network failure in React-Native, when device not connected to network.
My scenario is am trying to connect some api, while fetching request if network is disconnected react-native throws network request failed error. how to handle this scenario to give the user best user experience.
How to handle Network request failed in a better way.
Use NetInfo like this:
// Check for network connectivity
NetInfo.isConnected.fetch().done((isConnected) => {
if ( isConnected )
{
// Run your API call
}
else
{
// Ideally load from local storage
}
});