How to use the @react-native-community/netinfo.fetch function in @react-native-community/netinfo

To help you get started, we’ve selected a few @react-native-community/netinfo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pct-org / native-app / app / modules / IpFinder / IpFinder.js View on Github external
async componentDidMount() {
    const state = await NetInfo.fetch()

    let newState = {}
    newState.connectedToWifi = state.type === 'wifi' && state.isConnected

    let host = await AsyncStorage.getItem('@ipFinder.host')

    // Check if we have host or that current is still available and if we are connected to wifi
    // other check for host
    if ((!host || !(await this.isHost(host))) && newState.connectedToWifi) {
      host = null

      SplashScreen.hide()

      if (await deviceInfo.isEmulator()) {
        // If we are a emulator then check the host ip
        if (await this.isHost('10.0.2.2:5000')) {
github search-future / miyou.tv / src / utils / init / index.ts View on Github external
export default function init(store: Store) {
  BackHandler.addEventListener("hardwareBackPress", () => {
    const { nav }: { nav: NavigationState } = store.getState();
    const { index } = nav;
    if (index > 1) {
      store.dispatch(StackActions.pop({}));
      return true;
    }
    return false;
  });

  NetInfo.fetch().then(state => {
    store.dispatch(NetworkActions.update(state));
  });
  NetInfo.addEventListener(state => {
    if (typeof state === "object") {
      store.dispatch(NetworkActions.update(state));
    }
  });

  common(store);
}
github expo / expo / home / api / Connectivity.ts View on Github external
async isAvailableAsync(): Promise {
    if (this._isAvailable) {
      return this._isAvailable;
    }

    try {
      const netInfo = await NetInfo.fetch();
      this._isAvailable = netInfo.isConnected;
    } catch (e) {
      this._isAvailable = false;
      console.warn(`Uncaught error when fetching connectivity status: ${e}`);
    }

    return this._isAvailable;
  }
github microsoft / reactxp / extensions / netinfo / src / native-common / NetInfo.tsx View on Github external
isConnected(): Promise {
        return RNNetInfo.fetch().then((state: RNNetInfo.NetInfoState) => {
            return state.isConnected;
        }).catch(() => {
            return Promise.reject('NetInfo.isConnected.fetch() failed');
        });
    }
github microsoft / reactxp / extensions / netinfo / src / native-common / NetInfo.tsx View on Github external
getType(): Promise {
        return RNNetInfo.fetch().then((state: RNNetInfo.NetInfoState) => {
            return NetInfo._getNetworkTypeFromConnectionInfo(state);
        });
    }
github zzorba / ArkhamCards / components / core / withNetworkStatus.tsx View on Github external
_refreshNetworkStatus = () => {
      NetInfo.fetch().then(this._networkStatusChanged);
    };
github mattermost / mattermost-mobile / app / components / network_indicator / network_indicator.js View on Github external
connect = (displayBar = false) => {
        const {connection, startPeriodicStatusUpdates} = this.props.actions;
        clearTimeout(this.connectionRetryTimeout);

        NetInfo.fetch().then(async ({isConnected}) => {
            const {hasInternet, serverReachable} = await checkConnection(isConnected);

            connection(hasInternet);
            this.hasInternet = hasInternet;
            this.serverReachable = serverReachable;

            if (serverReachable) {
                this.statusUpdates = true;
                this.initializeWebSocket();
                startPeriodicStatusUpdates();
            } else {
                if (displayBar) {
                    this.show();
                }

                this.handleWebSocket(false);
github keybase / client / shared / actions / platform-specific / index.native.tsx View on Github external
const initOsNetworkStatus = async () => {
  const {type} = await NetInfo.fetch()
  return ConfigGen.createOsNetworkStatusChanged({isInit: true, online: type !== 'none', type})
}
github coreyphillips / moonshine / src / utils / helpers.js View on Github external
const isOnline = async () => {
	let isConnected = true;
	try {
		const connectionInfo = await NetInfo.fetch();
		if (connectionInfo.type === "none" || connectionInfo.type === "unknown") isConnected = false;
	} catch (e) {}
	return isConnected;
};