Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
anisimov74 opened this issue Jul 15, 2019 · 3 comments

Comments

@anisimov74
Copy link

anisimov74 commented Jul 15, 2019

deleted

@scarlac
Copy link

scarlac commented Jul 22, 2019

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
Copy link

scarlac commented Jul 22, 2019

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
Copy link

Gys commented Mar 15, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants