Issue
I have an Expo app using the Managed workflow. The app needs to check whether an internet connection is available.
- I can't
import { NetInfo } from 'react-native'
because that's deprecated. - I can't use react-native-community/react-native-netinfo because that uses native libraries, and you can't do that with an Expo managed app.
- I could eject, in order to use the above, but it doesn't seem like I should need to do that just to check if there's an internet connection.
- I can't use
navigator.onLine
because that global variable doesn't seem to be available. - I could make a trivial HTTP request to Google or my own server or whatever, and see if I get a response, but that only tests a connection to one site, and also it takes time and uses bandwidth.
What should I do?
Solution
Use NetInfo
of react-native
.
Yes, it is deprecated because they are planning on removing it in the next version of react-native
in favor of the community version. However, it is completely functional and can still be used for now, just make sure to check for breaking changes when the next versions of Expo SDK
are released.
It is likely that Expo will bring it into their managed workflow when react-native
removes it, or provide an alternative that won't require ejecting from Expo.
Answered By - Zaytri
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.