Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@react-native-community/netinfo: NativeModule.RNCNetInfo is null after install latest version

I have updated react native version from 0.57 to 0.59.1. After successful updated it throws error in react native info, so i installed @react-native-community/netinfo and removed Netinfo from react-native.

I have run below commands to install latest version of netinfo:

npm install --save @react-native-community/netinfo

react-native link @react-native-community/netinfo

cd ios && pod install

After successful linking when run my project i got error @react-native-community/netinfo: NativeModule.RNCNetInfo is null...

I also tried with version 3 of netinfo but same error occurred.

Version:

@react-native-community/netinfo: ^5.3.2

react: ^16.8.3

react-native": ^0.59.1

Please help me if anyone have solution for this.

Thanks.

like image 642
himanshu Avatar asked Jan 09 '20 12:01

himanshu


1 Answers

If you are getting this error while running jest test. Add following file to be used as a mock source
add a mock for the NetInfo bridge module and you need not update the Jest config...
file location ==> __mocks__/@react-native-community/netinfo.js

export default {
  getCurrentConnectivity: jest.fn(),
  isConnectionMetered: jest.fn(),
  addListener: jest.fn(),
  removeListeners: jest.fn(),
  isConnected: {
    fetch: () => {
      return Promise.resolve(true);
    },
    addEventListener: jest.fn(),
    removeEventListener: jest.fn(),
  },
};
like image 97
Akshay Vijay Jain Avatar answered Oct 27 '22 00:10

Akshay Vijay Jain