I am trying to check whether the user is connected to internet. I am using NetInfo like this (from the documentation):
componentDidMount() {
NetInfo.isConnected.addEventListener('change', this.handleConnectionChange);
NetInfo.isConnected.fetch().done(
(isConnected) => { this.setState({ status: isConnected }); }
);
}
componentWillUnmount() {
NetInfo.isConnected.removeEventListener('change', this.handleConnectionChange);
}
handleConnectionChange = (isConnected) => {
this.setState({ status: isConnected });
console.log(`is connected: ${this.state.status}`);
}
The strange is that the first time loading the screen where I am doing this is working fine. But when I start turning on/of my wifi the results are different: sometimes it detects the change sometime no. Someone having the same issue?
And if you're having trouble with your connection, you can run the Network troubleshooter to try and fix it. Select the Start button, then select Settings > Network & Internet > Status. Check your network connection status
Check your network connection status. Windows 10 lets you quickly check your network connection status. And if you're having trouble with your connection, you can run the Network troubleshooter to try and fix it. Select the Start button, then select Settings > Network & Internet > Status. Check your network connection status.
In case active probing fails, passive probing can also detect internet unless it’s disabled by GPO. Check below to make sure you didn’t disable passive probing. If it is, enable it and test again. Group Policy path: Computer Configuration\Administrative Templates\Network\Network Connectivity Status Indicator
Test your Wi-Fi on different devices If you’re on your laptop, pull out your phone or tablet to see if you can get internet over the same Wi-Fi connection. If it connects on one device but not the other, then you know that your internet connection is fine and it’s the disconnected device that’s having the problem.
In my experience, the iOS simulator doesn't 'notice' when the internet connection is re-connected when using the React Native NetInfo class.
It is rather annoying. However, for me it works as intended on a real device.
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