Guides
Plan-enterprise-icon
Expo Application Services
API Reference

NetInfo

@react-native-community/netinfo allows you to get information about connection type and connection quality.

Platform Compatibility

Android DeviceAndroid EmulatoriOS DeviceiOS SimulatorWeb
Status-success-iconStatus-success-iconStatus-success-iconStatus-success-iconStatus-success-icon

Installation

Terminal
→ npx expo install @react-native-community/netinfo

If you're installing this in a bare React Native app, you should also follow these additional installation instructions.

API

To import this library, use:
import NetInfo from '@react-native-community/netinfo';
If you want to grab information about the network connection just once, you can use:
NetInfo.fetch().then(state => {
  console.log('Connection type', state.type);
  console.log('Is connected?', state.isConnected);
});
Or, if you'd rather subscribe to updates about the network state (which then allows you to run code/perform actions anytime the network state changes) use:
const unsubscribe = NetInfo.addEventListener(state => {
  console.log('Connection type', state.type);
  console.log('Is connected?', state.isConnected);
});

// To unsubscribe to these update, just use:
unsubscribe();

Accessing the SSID

In order to access the ssid property (available under state.details.ssid), there are few additional configuration steps:

Android & iOS

  • Request location permissions with Location.requestPermissionsAsync()

iOS only

  • Add the com.apple.developer.networking.wifi-info entitlement to your app.json under ios.entitlements:
  "ios": {
    "entitlements": {
      "com.apple.developer.networking.wifi-info": true
    }
  }
For more information on API and usage, see react-native-netinfo documentation.
  • Message-iconAsk a question on the forums about NetInfo
  • Github-iconView open bug reports for NetInfo
  • Code-iconView source code for NetInfo
  • Build-iconView package in npm Registry
  • Edit-iconEdit this page

Was this doc helpful?