Open anisimov74 opened 5 years ago
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.
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.
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
deleted