useNetwork

A hook that can manage the state of network.

type NetworkState = {
  online?: boolean;
  since?: Date;
  rtt?: number;
  type?: string;
  downlink?: number;
  saveData?: boolean;
  downlinkMax?: number;
  effectiveType?: string;
};

const result: NetworkState = useNetwork();

Example

Basic usage of useNetwork hook.

API

PropertyDescriptionType
onlineEffective onlineboolean
sinceOnline/offline last change dateDate
rttRound-trip timenumber
typeType of connection that a device is using to communicate with the networkbluetooth | cellular | ethernet | none | wifi | wimax | other | unknown
downlinkEffective bandwidth estimate in megabits per secondnumber
downlinkMaxThe maximum downlink speednumber
saveDataWhether the user agent has set the option to reduce data usageboolean
effectiveTypeThe effective type of the connectionslow-2g | 2g | 3g | 4g
ON THIS PAGE