useNetworkInformation
Tracks network connectivity status and connection quality metrics (effectiveType, downlink, rtt, saveData) via the Network Information API.
Loading preview...
The useNetworkInformation hook subscribes to online/offline events and the browser's navigator.connection (NetworkInformation) API using useSyncExternalStore, exposing live connection speed, latency, and data-saver preferences.
Installation
Usage
Examples
Adaptive Media Quality (saveData and effectiveType)
Serve lower-resolution images or disable autoplay video when the user is on a slow connection (2g / slow-2g) or has Data Saver enabled.
Displaying Connection Diagnostics
Read downlink (Mbps) and rtt (round-trip time in ms) when isSupported is true.
API Reference
NetworkInformationState
Network connectivity and quality metrics returned by the hook.
Property
Specification
isOnlineunion
Whether the browser currently reports being online (
navigator.onLine)Full Signature
isSupportedunion
Whether the Network Information API (
navigator.connection) is supportedFull Signature
downlink?number
Effective bandwidth estimate in megabits per second
Full Signature
downlinkMax?number
Maximum downlink speed in megabits per second for the underlying connection technology
Full Signature
effectiveType?union
Effective connection type (
'slow-2g', '2g', '3g', or '4g')Full Signature
rtt?number
Estimated effective round-trip time of the current connection in milliseconds
Full Signature
saveData?union
Whether the user has requested a reduced data usage mode
Full Signature
type?union
Type of connection a device is using to communicate with the network
Full Signature