react-native-netinfo: NetInfo.fetch() crashes: RNCNetInfo.getCurrentState got 3 arguments, expected 2

Environment

System:
    OS: macOS Mojave 10.14.4
    CPU: (4) x64 Intel(R) Core(TM) i5-4308U CPU @ 2.80GHz
    Memory: 24.59 MB / 16.00 GB
    Shell: 5.3 - /bin/zsh
  Binaries:
    Node: 10.16.1 - /usr/local/bin/node
    Yarn: 1.15.2 - /usr/local/bin/yarn
    npm: 6.9.0 - /usr/local/bin/npm
  SDKs:
    iOS SDK:
      Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
  IDEs:
    Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.9.0 => 16.9.0
    react-native: https://github.com/expo/react-native/archive/sdk-36.0.1.tar.gz => 0.61.4
  npmGlobalPackages:
    react-native-cli: 2.0.1

Platforms

Both

Versions

Description

Whenever I try calling NetInfo.fetch() or NetInfo.addEventListener, app crashes. On iOS it just throws user to home screen, on Android there is following message:

RNCNetInfo.getCurrentState got 3 arguments, expected 2

Reproducible Demo

Following component is enough to cause app to crash.

import React from "react";
import { View, Text } from "react-native";
import NetInfo from "@react-native-community/netinfo";

class RootComponent extends React.Component {
  async componentDidMount(): void {
    const netInfoState = await NetInfo.fetch();

    console.log(netInfoState);
  }

  render() {
    return <View><Text>Hello</Text></View>;
  }
}

UPDATE:

I switched to version 5.0.0 and it works perfect.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 4
  • Comments: 16 (1 by maintainers)

Most upvoted comments

I had the same problem (SDK 36.0.0) and solved it by upgrading to react-native-community/netinfo version from 4.6.0 to 5.0.0.

  1. Delete the netinfo package: npm uninstall @react-native-community/netinfo npm uninstall @react-native-community/netinfo@4.6.0

  2. run expo start -> you will get an error, because no netinfo package is installed now

  3. stop expo -> Ctrl + C

  4. Install the new netinfo package: expo install @react-native-community/netinfo@5.0.0

  5. execute expo start

Now the problem should be solved

👋 @PiotrSzlagura If you’re using Expo then you’ll have to ask for support into their repo. This library is designed to work with React Native itself. I believe that Expo has added support for this library, but it’s likely you need to use a specific version for it to work. Their documentation should contain more details.

I’m closing this issue for now.

I’m still getting this error on my android device even after upgrading to the latest version 5.9.5. I’m using expo to run the native project and i followed the steps mentioned in expo docs https://docs.expo.io/versions/latest/sdk/netinfo/. If someone has a fix please post it here versions “react-native”: “SDK 35 (0.59.8)”, “@react-native-community/netinfo”: “^5.9.5”,

Hello guys,

$ npm install @react-native-community/netinfo@5.3.2

This version worked for me

Getting similar error

RNCNetInfo.getCurrentState was called with 0 arguments but expects 1 arguments. 
If you haven't changed this method yourself, this usually means that your versions
of the native code and JavaScript code are out of sync. 
Updating both should make this error go away.

I am not using expo, running on iOS simulator iPhone 11 I deleted and installed node_modules, Pods, Podfile.lock, cleaned build folder

versions “react-native”: “0.61.5”, “@react-native-community/netinfo”: “^5.3.3”,

Last working version seems to be the 5.1.0

Hey guys, Expo 37 user here. I tried a bunch of different version, including the recommended Expo version “5.5.1” (that’s what expo install @react-native-community/netinfo gave me) but all return the RNC error. Any ideas? Anyone who got it working with Expo 37?

@mikehardy apologies if this is the wrong place to ask this, I can ask it in the Expo forums or slack if that’s better.

That’s a long time known issue, yes, it was not introduced with recent version 5.2.0. My issue is (as was yours) about a red screen with the error above since version after 5.5.0. I don’t think a red screen falls into category of known issue.