| id | netinfo |
|---|---|
| title | NetInfo |
| layout | docs |
| category | APIs |
| permalink | docs/netinfo.html |
| next | panresponder |
| previous | linking |
NetInfo exposes info about online/offline status.
NetInfo.fetch().done((reach) => {
console.log('Initial: ' + reach);
});
function handleFirstConnectivityChange(reach) {
console.log('First change: ' + reach);
NetInfo.removeEventListener(
'change',
handleFirstConnectivityChange
);
}
NetInfo.addEventListener(
'change',
handleFirstConnectivityChange
);ConnectionType describes the type of connection the device is using to communicate with the network.
Disconnected- device is offlineWiFi- device is online and connected via wifiCellular- device is connected via Edge, 3G, WiMax, or LTEEthernet- device is online and connected via cableBluetooth- device is online and connected via bluetoothNetProxy- device is online and connected via proxy
NetInfo.addEventListener(eventName, handler)Adds an event handler. Supported events:
connectionChange: Fires when the network status changes. The argument to the event handler is an object with keys:type: AConnectionType(listed above)effectiveType: AnEffectiveConnectionType(listed above)
change: This event is deprecated. Listen toconnectionChangeinstead. Fires when the network status changes. The argument to the event handler is one of the deprecated connectivity types listed above.
NetInfo.removeEventListener(eventName, handler)Removes the listener for network status changes.
Available on all platforms. Asynchronously fetch a boolean to determine internet connectivity.
NetInfo.isConnected.fetch().then(isConnected => {
console.log('First, is ' + (isConnected ? 'online' : 'offline'));
});
function handleFirstConnectivityChange(isConnected) {
console.log('Then, is ' + (isConnected ? 'online' : 'offline'));
NetInfo.isConnected.removeEventListener(
'connectionChange',
handleFirstConnectivityChange
);
}
NetInfo.isConnected.addEventListener(
'connectionChange',
handleFirstConnectivityChange
);