olofd / react-native-device-log

A UI and service for handling/displaying dev log messages on devices
101 stars 55 forks source link

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

Open anisimov74 opened 5 years ago

anisimov74 commented 5 years ago

deleted

scarlac commented 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.

scarlac commented 5 years ago

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.

Gys commented 4 years ago

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