Command palette

@yasinsensoy/native

React Native · APIs and utilities

Network

Network state.

4 exports

Import

import { Network, useNetworkState } from "@yasinsensoy/native";

Network

module

Network state.

NameTypeDescription
getState() => Promise<NetworkState>The current state.
addListener(listener: (state: NetworkState) => void) => () => voidCalled when the state changes. Returns a function that ends the subscription.

Watches the network state (null until the first value arrives).

useNetworkState(): NetworkState | null

Connection type.

type NetworkType = "wifi" | "cellular" | "ethernet" | "bluetooth" | "vpn" | "other" | "none"

NetworkState

interface

Network state.

NameTypeDescription
connectedbooleanWhether it is connected to a network.
internetReachablebooleanWhether the internet is reachable. Android validates the network (false on Wi-Fi with a captive portal); iOS does not, it is the same as connected.
typeNetworkTypeConnection type.
expensivebooleanA metered connection (cellular data, hotspot). Defer large downloads.
constrainedbooleanData saver is on (iOS Low Data Mode, Android Data Saver).