One Logo Pool Ball
wwwwwwwwwwwwwwwwwww

Network

Connection state and reachability

Connection state through One.Network. Backed by NWPathMonitor on iOS, ConnectivityManager with a NetworkCallback on Android, and navigator.onLine with online/offline events on web.

import { One, useNetworkState } from 'one'
import { Text } from 'react-native'
const state = await One.Network.getState()
// { type: 'wifi', isConnected: true, isInternetReachable: true }
const subscription = One.Network.addStateListener((next) => {
console.log(next.type)
})
subscription.remove()
function NetworkStatus() {
const live = useNetworkState()
return <Text>{live.type}</Text>
}

type is one of none, unknown, cellular, wifi, bluetooth, ethernet, wimax, vpn, or other. On web a live connection reports unknown, since browser connection types are unreliable.

getState() returns Promise<NetworkState>. useNetworkState() returns the same shape as React state and removes its listener on unmount. On native, the hook starts with unknown and both flags false, then updates from the initial read and native events. Once an event arrives, a pending initial read cannot overwrite it. addStateListener(callback) returns a subscription whose remove() stops that callback. Native listeners share a monitor started by its first subscriber; later subscribers receive subsequent changes. Use getState() when you need an initial connection reading.

PropsTypeDescription
typeNetworkStateTypeConnection transport, or none for a disconnected path.
NetworkStateTypeConnection transport, or none for a disconnected path.
isConnectedbooleanWhether the system reports an internet-capable connection.
booleanWhether the system reports an internet-capable connection.
isInternetReachablebooleanThe platform connectivity signal described below.
booleanThe platform connectivity signal described below.

On iOS, both flags are true when NWPathMonitor reports a satisfied path. On Android, isConnected reads NET_CAPABILITY_INTERNET and isInternetReachable reads NET_CAPABILITY_VALIDATED. On web, both flags follow navigator.onLine. These values describe system connectivity; One does not send an HTTP request to determine them.

PropsTypeDescription
remove() => voidUnsubscribe this connection-state callback.
() => voidUnsubscribe this connection-state callback.

The library manifest declares ACCESS_NETWORK_STATE (a normal install-time permission, merged into the app automatically).

Edit this page on GitHub.