[addEventListener][iOS] addEventListener only triggers for the first time(s).
See original GitHub issueEnvironment
System:
OS: macOS 12.3.1
CPU: (8) x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
Memory: 294.72 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 14.17.0 - /usr/local/bin/node
Yarn: 1.22.18 - /usr/local/bin/yarn
npm: 8.6.0 - /usr/local/bin/npm
Watchman: 2022.03.21.00 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.11.3 - /Users/mo/.rvm/rubies/ruby-2.7.4/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.2, iOS 15.2, macOS 12.1, tvOS 15.2, watchOS 8.3
Android SDK: Not Found
IDEs:
Android Studio: 2021.1 AI-211.7628.21.2111.8193401
Xcode: 13.2.1/13C100 - /usr/bin/xcodebuild
Languages:
Java: 11.0.13 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 18.1.0 => 18.1.0
react-native: 0.68.2 => 0.68.2
react-native-macos: Not Found
npmGlobalPackages:
*react-native*: Not Found
Platforms
iOS
Versions
- iOS: 15.4.1
- react-native-netinfo: 8.3.0
- react-native: 0.68.2
- react: 18.1.0
Description
addEventListener triggers only for the first time/ first couple times that connection changes. After that it doesn’t trigger the event.
Reproducible Demo
Use following code:
useEffect(() => {
NetInfo.addEventListener((networkState) => {console.log(networkState)}
}, [])
Try to switch the wifi on and off for more than 4-5 times. See if it triggers all the events.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
javascript - AddEventListener only triggers once - Stack Overflow
The problem is in your condition. "green" always evaluates to true as it is a non-empty string. What you want to do is...
Read more >EventTarget.addEventListener() - Web APIs | MDN
The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered ...
Read more >How to ensure an event listener is only fired once in JavaScript
1. Using the once option. We can pass an object as an argument to the addEventListener method and specify that the event is...
Read more >JavaScript/TypeScript: addEventListener triggers immediately
By adding the { capture: true } option to the new event listener, it will only trigger in the capturing phase, and by...
Read more >One-off event listeners in JavaScript | by Ashwani Gupta
Before explaining what one time event listeners are, we have to first ... The second way is to call the addEventListener() method on...
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
@mhatami-ecotrak Are you able to reproduce this bug on a physical device? I tried your demo on a simulator, and it was buggy, but I could not reproduce it on a physical device.
(You will have to run the app from Xcode and watch the logs there because you’ll get disconnected from the Metro server doing this test)
@mikehardy V6 didn’t work either.