question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

addEventListener not updated when connection change

See original GitHub issue

Platforms

Android and iOS

Versions

  • react-native-netinfo: 7.1.11
  • react-native: 0.63.4
  • react: 17.0.1

Description

I updated the NetInfo library from 6.0.0 to the last one, but addEventListener not working if the status connection change. I think better version 6.0.0 for the update listener.

and I go back to using 6.0.0

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:19
  • Comments:53 (20 by maintainers)

github_iconTop GitHub Comments

35reactions
castrololcommented, Feb 24, 2022

Platforms

Android

Versions

  • react-native-netinfo: 7.1.12
  • react-native: 0.63.3
  • react: 16.13.1

Hey folks, I noticed when I start the application with network and turn on airplane mode, the value of const { isConnected } = useNetInfo() is not updated and if I start with airplane mode turned on, and turn it off, same issue. ` In my case I cannot upgrade the react-native version cause I’m using expo, so I made a patch to solve that issue on older versions.

you can install patch-package

then go to the file node_modules/@react-native-community/netinfo/android/src/main/java/com/reactnativecommunity/netinfo/ConnectivityReceiver.java and remove that condition https://github.com/react-native-netinfo/react-native-netinfo/blob/6b01fee211df160d0afce70c5955681c75b24a5a/android/src/main/java/com/reactnativecommunity/netinfo/ConnectivityReceiver.java#L100

and then remember to put patch-package command on postinstall script, you can check it here

then run npx patch-package @react-native-community/netinfo

it’s working fine for me on android and didn’t create issues on ios!

21reactions
mikehardycommented, Feb 24, 2022

…or you can update to modern react-native versions, react-native is on 0.67.3 now, I cannot imagine using 0.63 at this point, it was released so long ago

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Native - NetInfo.addEventListener not triggering when ...
I am trying to implement a offline (and yet to be added - but also a low connection) network error ...
Read more >
NetworkInformation: change event - Web APIs | MDN
The change event fires when connection information changes, and the event is received by the NetworkInformation object.
Read more >
NetInfo - React Native Archive
addEventListener (). NetInfo. ... connectionChange : Fires when the network status changes. ... Detect if the current active connection is metered or not....
Read more >
React Native NetInfo - To Get Internet Connection Status
addEventListener (state => { console.log( 'Connection type: ' + state.type + ', Is connected?: ' + state. ... To Unsubscribe from the Network...
Read more >
How to Handle Network Connection in Your React Native App
isInternetReachable — A Boolean value that determines whether or not the internet can be accessed using the current connection.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found