useNetwork
A hook to get the network state
Loading...
Installation
npx shadcn@latest add @shadcnhooks/use-networkAPI
/**
* @see https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation
* The network state
*/
export interface NetworkState {
/**
* The date when the network state was last updated
*/
since?: Date
/**
* Whether the network is online
*/
online?: boolean
/**
* The round-trip time in milliseconds
*/
rtt?: number
/**
* The type of the network
*/
type?: string
/**
* The downlink speed in Mbps
*/
downlink?: number
/**
* Whether the user has enabled data saving
*/
saveData?: boolean
/**
* The maximum downlink speed in Mbps
*/
downlinkMax?: number
/**
* The effective type of the network
*/
effectiveType?: string
}
/**
* A hook to get the network state
* @returns The network state
*/
export function useNetwork(): NetworkStateCredits
Last updated on