fn

useNetwork

v0.0.14testeddemo

Reactive Network Information API state plus online/offline status.

Example

ts
const { isOnline, offlineAt, downlink, effectiveType, saveData, type } = useNetwork();

Demo

Loading demo…

Signature

ts
export function useNetwork(options: UseNetworkOptions ={ ... }

Parameters

ParameterTypeDescription
options?UseNetworkOptionsOptions

Returns

UseNetworkReturnReactive online status, transition timestamps, and connection info
PropertyTypeDescription
isSupportedReadonly<ShallowRef<boolean>>Whether the Network Information API (navigator.connection) is supported.
isOnlineReadonly<ShallowRef<boolean>>Whether the browser is currently online (navigator.onLine).
offlineAtReadonly<ShallowRef<number | undefined>>The timestamp of the last time the browser went offline, in ms.
onlineAtReadonly<ShallowRef<number | undefined>>The timestamp of the last time the browser came back online, in ms.
downlinkReadonly<ShallowRef<number | undefined>>The estimated effective bandwidth in megabits per second.
downlinkMaxReadonly<ShallowRef<number | undefined>>The maximum downlink speed of the underlying connection technology, in Mbps.
effectiveTypeReadonly<ShallowRef<NetworkEffectiveType>>The effective type of the connection (slow-2g, 2g, 3g, or 4g).
rttReadonly<ShallowRef<number | undefined>>The estimated effective round-trip time of the current connection, in ms.
saveDataReadonly<ShallowRef<boolean | undefined>>Whether the user has requested a reduced data usage mode.
typeReadonly<ShallowRef<NetworkType>>The type of connection a device is using to communicate with the network.