Browser APIs
useNetworkInformation
About
React hook for detecting network connection quality and type using the Network Information API. Provides information about the user's connection including speed, type, and data saver mode.
Installation
Usage
Return Value
Returns an object with the following properties:
| Property | Type | Description |
|---|---|---|
| type | ConnectionType | null | Network connection type (wifi, cellular, etc.) |
| effectiveType | EffectiveConnectionType | null | Effective connection type (4g, 3g, 2g, slow-2g) |
| downlink | number | null | Downlink speed in Mbps |
| downlinkMax | number | null | Maximum downlink speed in Mbps |
| rtt | number | null | Round trip time in milliseconds |
| saveData | boolean | Whether data saver mode is enabled |
| isSupported | boolean | Whether Network Information API is supported |
Connection Types
"bluetooth"- Bluetooth connection"cellular"- Cellular network (3G, 4G, 5G)"ethernet"- Wired ethernet connection"wifi"- WiFi connection"wimax"- WiMAX connection"none"- No network connection"other"- Other connection type"unknown"- Connection type unknown
Effective Connection Types
"slow-2g"- Very slow connection (~50 Kbps)"2g"- Slow connection (~70 Kbps)"3g"- Medium connection (~700 Kbps)"4g"- Fast connection (≥700 Kbps)
Examples
Adaptive Content Loading
Data Saver Warning
Network-Aware Features
Features
- Real-time updates - Automatically updates when network changes
- Connection type - Detect WiFi, cellular, ethernet, etc.
- Speed detection - Get downlink speed and RTT measurements
- Data saver mode - Respect user's data saving preferences
- Adaptive loading - Load appropriate content based on connection
- TypeScript support - Full type definitions included
Browser Support
The Network Information API is supported in:
- Chrome 61+
- Edge 79+
- Opera 48+
- Samsung Internet 8.0+
Note: Firefox and Safari do not currently support this API.
Notes
- Values may be
nullif not available effectiveTypeis based on observed RTT and downlink values- Data saver mode indicates user preference for reduced data usage
- Connection information updates automatically when network changes
- Use this for adaptive loading, not for tracking users
- Respecting
saveDataprovides better user experience