I have an issue with the react-native-community/netinfo package
My react-native-community/netinfo version is 9.5.0, and my react native version is 0.70.7.
The react version is 18.1.0
I use isInternetReachable to detect internet reachability and the problem is when I connect with Wi-Fi, but with no data connection the isInternetReachable still returns true. How can I fix it?
I tried every listeners and every possible way that i found in the documentation, but I'm not getting a result.
Can someone help me figure out how to do this?
NetInfo streams the updates from the native side directly w/o any computation. This sometimes brings undesired behavior.
https://github.com/react-native-netinfo/react-native-netinfo?tab=readme-ov-file#addeventlistener
Solution
Netinfo can ping you up to 5+ times whenever the network state is changed, what works for me is to debounce the event listener response for a second, this way it is working as expected. Also, the library doesn't work with iOS Simulator well, you need to test it on a real device.
If you want to solve the issue when the network connection is coming from a hotspot.
You need to use not only
isConnectedflat but alsoisInternetReachable. If that is not working for you, you can apply a logic where every time netInfo returns isConnected && isInternetReachable true, you can integrate https://www.npmjs.com/package/react-native-ping and do a double-check, after your event listener emits