/** * Network connection types */ type ConnectionType = "bluetooth" | "cellular" | "ethernet" | "none" | "wifi" | "wimax" | "other" | "unknown"; /** * Effective connection types */ type EffectiveConnectionType = "slow-2g" | "2g" | "3g" | "4g"; /** * Network information data */ interface NetworkInfo { /** * Network connection type (wifi, cellular, etc.) */ type: ConnectionType | null; /** * Effective connection type (4g, 3g, 2g, slow-2g) */ effectiveType: EffectiveConnectionType | null; /** * Downlink speed in Mbps */ downlink: number | null; /** * Maximum downlink speed in Mbps */ downlinkMax: number | null; /** * Round trip time in milliseconds */ rtt: number | null; /** * Whether data saver mode is enabled */ saveData: boolean; } /** * Return value for the useNetworkInformation hook */ interface UseNetworkInformationReturnValue extends NetworkInfo { /** * Whether the Network Information API is supported */ isSupported: boolean; } /** * useNetworkInformation hook * * Network connection quality and type detection using the Network Information API. * Provides information about the user's connection including speed, type, and data saver mode. * * @returns Object containing network information * * @example * ```tsx * import { useNetworkInformation } from "rooks"; * * function NetworkStatus() { * const { effectiveType, downlink, rtt, saveData, isSupported } = useNetworkInformation(); * * if (!isSupported) { * return
Network Information API not supported
; * } * * return ( *
*

Network Status

*

Connection Type: {effectiveType}

* {downlink &&

Download Speed: {downlink} Mbps

} * {rtt &&

Round Trip Time: {rtt} ms

} * {saveData &&

Data Saver Mode: Enabled

} *
* ); * } * ``` * * @see https://rooks.vercel.app/docs/hooks/useNetworkInformation */ declare function useNetworkInformation(): UseNetworkInformationReturnValue; export { useNetworkInformation }; export type { UseNetworkInformationReturnValue, NetworkInfo, ConnectionType, EffectiveConnectionType, };