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.

NetInfo.addEventListener not receiving network change events on Android emulator

See original GitHub issue

Environment

System:
    OS: macOS Mojave 10.14.6
    CPU: (8) x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
    Memory: 20.16 MB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 10.16.3 - ~/.nvm/versions/node/v10.16.3/bin/node
    Yarn: 1.17.0 - /usr/local/bin/yarn
    npm: 6.9.0 - ~/.nvm/versions/node/v10.16.3/bin/npm
    Watchman: 4.7.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
    Android SDK:
      API Levels: 19, 22, 23, 24, 25, 26, 27, 28
      Build Tools: 22.0.1, 23.0.1, 23.0.3, 25.0.0, 25.0.2, 27.0.3, 28.0.0, 28.0.2, 28.0.3
      System Images: android-19 | ARM EABI v7a, android-22 | Google APIs Intel x86 Atom, android-23 | Google APIs Intel x86 Atom, android-25 | Google APIs Intel x86 Atom, android-27 | Google APIs Intel x86 Atom, android-28 | Google APIs Intel x86 Atom, android-28 | Google Play Intel x86 Atom, android-28 | Google Play Intel x86 Atom_64, android-30 | Google Play Intel x86 Atom
  IDEs:
    Android Studio: 4.0 AI-193.6911.18.40.6514223
    Xcode: 10.1/10B61 - /usr/bin/xcodebuild
  npmGlobalPackages:
    react-native-cli: 2.0.1

Platforms

Works fine on iOS. Doesn’t work on two android emulators.

  • Nexus 5 api 6
  • Pixel 3 api 11

Versions

  • expo: 37
  • react native: 0.61.4
  • react: 16.9.0
  • react-native-netinfo: 5.9.4

Description

When I render my component, the addEventListener is always detecting isInternetReachable: true even when I turn off my laptop’s wifi. When I toggle the wifi on and off, the event doesn’t fire. This works fine on iOS emulator.

Reproducible Demo

Here is the code I use

  import NetInfo from '@react-native-community/netinfo'

  const [isInternetReachable, setIsInternetReachable] = useState(true)

  useEffect(() => {
    const unsubscribe = NetInfo.addEventListener((state) => {
        setIsInternetReachable(state.isInternetReachable ?? false)
    })

    return () => {
      unsubscribe()
    }
  }, [])

I hope that’s enough information

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:27
  • Comments:17 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
DanielRieracommented, Feb 4, 2022

Work fine 6.2.1 version

2reactions
githuboftigrancommented, Feb 1, 2022

addEventListener callback is not called. Guys… you had one job…

Read more comments on GitHub >

github_iconTop Results From Across the Web

NetInfo.addEventListener not receiving network change ...
I am facing the same issue in Pixel 5a. NetInfo.addEventListener is not receiving any change events when I enabled airplane mode. It's 8.2.0 ......
Read more >
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 >
NetInfo - React Native Archive
NetInfo exposes info about online/offline status. ... Supported events: connectionChange : Fires when the network status changes. The argument to the event ......
Read more >
@react-native-community/netinfo - npm
There is a known issue with the iOS Simulator which causes it to not receive network change notifications correctly when the host machine ......
Read more >
NetInfo - Expo Documentation
Android Device, Android Emulator, iOS Device, iOS Simulator, Web ... then allows you to run code/perform actions anytime the network state changes) use:...
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