network
Track connectivity and connection quality.
| Package | @vizejs/composable/network |
| Own the source | vize lib pull composable:network |
| Runtime exports | useNetwork, useOnline |
| Gzip budget | 1792 B |
Usage
import { useNetwork, useOnline } from "@vizejs/composable/network";
Runtime contract
| Utility | Category | Stability | SSR | Hydration | Cleanup | Targets | Host globals | Uses |
|---|---|---|---|---|---|---|---|---|
useNetwork |
networking | experimental | deterministic-fallback | caller-managed | reactive-scope | web, desktop | window |
tryOnScopeDispose |
useOnline |
networking | experimental | deterministic-fallback | caller-managed | reactive-scope | web, desktop | window |
useNetwork |
API
useNetwork
Track connectivity and connection quality. Listens for online/offline on the window and change on navigator.connection where available. Unknown or future enum values normalize to null so the public unions stay closed. Server renders report ssrOnline with every quality metric null. Inside a component the connection is read after mounting, so hydration renders the server values first. Listeners are removed with the owning reactive scope.
function useNetwork(options: UseNetworkOptions = {}): NetworkControls
useOnline
Track whether the browser reports being online. Shorthand for useNetwork(options).isOnline with the same SSR fallback and cleanup semantics.
function useOnline(options: UseNetworkOptions = {}): Readonly<Ref<boolean>>
Types
NetworkInformationLike
Subset of the (non-standard) NetworkInformation interface.
| Member | Type | Description |
|---|---|---|
downlink? |
number |
Estimated downlink bandwidth in Mbit/s. |
downlinkMax? |
number |
Maximum downlink bandwidth in Mbit/s. |
effectiveType? |
string |
Effective connection class. |
rtt? |
number |
Estimated round-trip time in milliseconds. |
saveData? |
boolean |
Whether the user requested reduced data usage. |
type? |
string |
Physical connection type. |
NetworkHost
Window-like capability observed by the network composables.
| Member | Type | Description |
|---|---|---|
navigator |
{ /** Whether the browser believes it is online. */ readonly onLine: boolean; /** Network Information API object, where supported. */ readonly connection?: NetworkInformationLike; } |
Navigator exposing connectivity. |
UseNetworkOptions
Options shared by useOnline and useNetwork.
| Member | Type | Description |
|---|---|---|
ssrOnline? |
boolean |
Connectivity exposed during server rendering. |
host? |
MaybeRefOrGetter<NetworkHost | null | undefined> |
Reactive window capability for alternate runtimes and tests. |
NetworkControls
Reactive network state returned by useNetwork.
| Member | Type | Description |
|---|---|---|
isSupported |
Readonly<Ref<boolean>> |
Whether the Network Information API is available. false during server rendering. |
isOnline |
Readonly<Ref<boolean>> |
Whether the browser reports being online. |
onlineAt |
Readonly<Ref<number | null>> |
Epoch milliseconds of the latest online event. |
offlineAt |
Readonly<Ref<number | null>> |
Epoch milliseconds of the latest offline event. |
downlink |
Readonly<Ref<number | null>> |
Estimated downlink in Mbit/s. |
downlinkMax |
Readonly<Ref<number | null>> |
Maximum downlink in Mbit/s. |
effectiveType |
Readonly<Ref<NetworkEffectiveType | null>> |
Effective connection class, or null when unknown. |
rtt |
Readonly<Ref<number | null>> |
Estimated round-trip time in milliseconds. |
saveData |
Readonly<Ref<boolean>> |
Whether the user requested reduced data usage. |
type |
Readonly<Ref<NetworkConnectionType | null>> |
Physical connection type, or null when unknown. |