daily-toolset
Version:
A lightweight, versatile collection of TypeScript utility functions for everyday development needs. Simplify and streamline your Node.js, React, and Next.js projects with a powerful suite of well-organized helpers for strings, arrays, dates, objects, and
46 lines (45 loc) • 1.46 kB
TypeScript
type NetworkData = {
online: boolean;
rtt?: number;
downlink?: number;
downlinkMax?: number;
effectiveType?: "slow-2g" | "2g" | "3g" | "4g";
saveData?: boolean;
networkType?: "bluetooth" | "cellular" | "ethernet" | "wifi" | "wimax" | "none" | "other" | "unknown";
};
/**
* useNetwork
*
* A hook to get the current network information.
*
* It returns an object with the following properties:
* - online: a boolean indicating if the browser is online or not.
* - rtt: the round trip time in milliseconds of the current connection.
* - downlink: the estimated effective bandwidth in megabits per second of the
* current connection in megabits per second.
* - downlinkMax: the maximum downlink speed in megabits per second of the
* current connection.
* - effectiveType: the effective type of the connection, which is one of the
* following:
* - "slow-2g"
* - "2g"
* - "3g"
* - "4g"
* - saveData: a boolean indicating if the user has requested a reduced data
* usage mode.
* - networkType: the type of the connection, which is one of the following:
* - "bluetooth"
* - "cellular"
* - "ethernet"
* - "wifi"
* - "wimax"
* - "none"
* - "other"
* - "unknown"
*
* The hook updates the returned value when the connection type changes.
*
* @returns {NetworkData} an object with the current network information.
*/
export declare function useNetwork(): NetworkData;
export {};