Currently I am using NetInfo of react-native and with the help of EffectiveConnectionType, I am able to find the connection is in : 2g, 3g, 4g and unknown. But is there any optimise way to handle this problem ?
You can use https://github.com/rgommezz/react-native-offline or you can simply add timeout in axios...if request is aborted after particular time say 10 sec... re-hit the same API request and set the count limit if count limit exceeds... You can show the slow internet message. Save this answer.
If you just want to know whether the device has an active internet connection, you can use e.g. isConnected from React Native's NetInfo: import { NetInfo } from "react-native"; NetInfo.
NetInfoState APItype – Returns the NetInfoStateType of the current connection (cellular, wifi, bluetooth, etc..) isConnected – Boolean value that tells if there is an active network connection. isWifiEnabled (Android only) – Boolean value indicating if wifi is enabled or not.
You can use https://github.com/rgommezz/react-native-offline or you can simply add timeout in axios...if request is aborted after particular time say 10 sec...re-hit the same API request and set the count limit if count limit exceeds...You can show the slow internet message.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With