This API allows you to get information about connection type and connection quality.
Platform Compatibility
Android Device | Android Emulator | iOS Device | iOS Simulator | Web |
---|
✅ | ✅ | ✅ | ✅ | ✅ |
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);
});
unsubscribe();