Listener not firing when getting internet connection back.
See original GitHub issueEnvironnement
react-native info
System:
OS: macOS 10.15.5
CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 33.56 MB / 16.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 13.7.0 - ~/.nvm/versions/node/v13.7.0/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 6.14.5 - ~/.nvm/versions/node/v13.7.0/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 13.7, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
Android SDK:
API Levels: 23, 28, 29
Build Tools: 28.0.3, 29.0.2
System Images: android-27 | Google Play Intel x86 Atom, android-28 | Intel x86 Atom_64, android-28 | Google APIs Intel x86 Atom, android-28 | Google Play Intel x86 Atom, android-29 | Intel x86 Atom_64, android-29 | Google APIs Intel x86 Atom
IDEs:
Android Studio: 3.5 AI-191.8026.42.35.6010548
Xcode: 11.7/11E801a - /usr/bin/xcodebuild
npmPackages:
react: 16.9.0 => 16.9.0
react-native: 0.61.5 => 0.61.5
npmGlobalPackages:
react-native-cli: 2.0.1
react-native: 0.61.5
Platforms
Android & iOS
Versions
- Android: 9
- iOS: 13.6.1
- react-native-netinfo: 5.9.2
- react-native: 0.61.5
- react: 16.9.0
Description
I wired up a listener to know wether internet is reachable from the app. When there i no internet connection the listener fire as espected but when the internet connection comes back, the listener does not fire and the app still consider that internet is not available but the device has internet (email notification).
Reproducible Demo
componentDidMount() {
...
this._networkInfosListener = NetInfo.addEventListener(state => {
this.setState({isInternetReachable: state.isInternetReachable});
});
...
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:26
- Comments:54 (12 by maintainers)
Top Results From Across the Web
React Native - NetInfo.addEventListener not triggering when ...
My issue is that the error message displays no problem when disconnecting the simulators network. Both the console log messages and the ...
Read more >Event listeners not working? 3 key areas to troubleshoot
In this post, CookiesHQ Tech Lead Romaric guides us through the three key areas for troubleshooting to get everything working as it should....
Read more >Troubleshoot your Network Load Balancer
The following information can help you troubleshoot issues with your Network Load Balancer. A registered target is not in service. If a target...
Read more >How to Handle Network Connection in Your React Native App
Your app may need to detect the user's internet connectivity at times. ... use event listeners in your component to get network connection ......
Read more >EventTarget.removeEventListener() - Web APIs | MDN
Return value. None. Matching event listeners for removal. Given an event listener previously added by calling addEventListener() , ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@mikehardy @matt-oakes I’ve set up a repo with a minimal example, tested on Android 9, the listener doesn’t fire: https://github.com/anyamiletic/rn-network-info-demo I honestly don’t understand the animosity towards the people who comment +1 - type comment on this issue, it’s keeping it from being buried and ignored, and it is a major problem that needs addressing. I’ve noticed these offhand and angry comments on other issues as well, and while i understand that you are doing this on a voluntary basis, i feel like that kind of attitude is unwarranted. Thank you for looking into this.
Thank you. In the meantime my team has found that using
useNetInfo
hook actually works as expected, and the changes are being registered. So we changed our code to something like this:to simulate the event listener. Maybe this helps narrow the issue down, since this works and the eventListener doesn’t.