react-native-device-log icon indicating copy to clipboard operation
react-native-device-log copied to clipboard

Import NetInfo from '@react-native-community/netinfo' module instead of `react-native`.

Open anisimov74 opened this issue 5 years ago • 3 comments

deleted

anisimov74 avatar Jul 15 '19 09:07 anisimov74

From RN 0.60 and forward, this library no longer works, since NetInfo has been entirely removed. The import will result in undefined, causing the error:

undefined is not an object (evaluating '_reactNative.NetInfo.addEventListener')

I know of no workaround, beyond patching or forking this library. Library seems unmaintained.

scarlac avatar Jul 22 '19 05:07 scarlac

Found a workaround. Add the following to /index.js (or whatever you defined in package.json as "main": "index.js"):

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

// Monkey-patch unmaintained react-native-device-log to work with RN 0.60
// where NetInfo was removed entirely
// https://github.com/olofd/react-native-device-log/issues/23#issuecomment-513654702
ReactNative.NetInfo = NetInfo;

Update: This may not work for everyone. I found it worked on Android but did not work on iOS.

scarlac avatar Jul 22 '19 06:07 scarlac

There are several forks that made the neccessary changes for NetInfo. For example I used:

npm install https://github.com/Trihydro/react-native-device-log

Gys avatar Mar 15 '20 10:03 Gys