react-native-netinfo library get error when internet disconnect

Please provide the following:

  1. SDK Version:
    package.json
    {

“main”: “node_modules/expo/AppEntry.js”,

“scripts”: {

"start": "expo start",

"android": "expo start --android",

"ios": "expo start --ios",

"web": "expo start --web",

"eject": "expo eject"

},

“dependencies”: {

"@react-native-community/masked-view": "0.1.6",

"@react-native-community/netinfo": "5.5.1",

"@react-navigation/native": "^5.1.6",

"@react-navigation/stack": "^5.2.11",

"expo": "~37.0.3",

"react": "~16.9.0",

"react-dom": "~16.9.0",

"react-native": "https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz",

"react-native-gesture-handler": "~1.6.0",

"react-native-reanimated": "~1.7.0",

"react-native-safe-area-context": "0.7.3",

"react-native-screens": "~2.2.0",

"react-native-web": "~0.11.7"

},

“devDependencies”: {

"@babel/core": "^7.8.6",

"babel-preset-expo": "~8.1.0"

},

“private”: true

}

  1. Platforms(Android/iOS/web/all):
    Issue related to Android

App.js
import React, {useEffect, useState} from ‘react’;

import { StyleSheet, Text, View } from ‘react-native’;

import NetInfo from ‘@react-native-community/netinfo’;

export default function App() {

const [name, setName] = useState(“”)

useEffect(() => {

const unsubscribe = NetInfo.addEventListener(state => {

  console.log('Is connected?', state.isConnected);

  setName(state.isConnected);

}, []);

return () => {

  unsubscribe();

}

});

return (

<View style={styles.container}>

  <Text

  >{name}</Text>

</View>

);

}

const styles = StyleSheet.create({

container: {

flex: 1,

backgroundColor: '#fff',

alignItems: 'center',

justifyContent: 'center',

},

});

android emulator works fine. but physical device got error.

getting this error when internet disconnect
red screen error: java.lang.illegalStateException:WebSocket connection no longer valid

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.