{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "use-network",
  "title": "useNetwork",
  "description": "A hook to get the network information",
  "files": [
    {
      "path": "registry/hooks/use-network.ts",
      "content": "'use client'\n\nimport * as React from 'react'\n\ninterface NavigatorWithConnection extends Navigator {\n  connection?: NetworkInformation\n}\n\ninterface NetworkInformation extends EventTarget {\n  downlink: number\n  downlinkMax?: number\n  effectiveType: 'slow-2g' | '2g' | '3g' | '4g'\n  rtt: number\n  saveData: boolean\n  type?: 'bluetooth' | 'cellular' | 'ethernet' | 'none' | 'wifi' | 'wimax' | 'other' | 'unknown'\n  addEventListener: (type: 'change', listener: () => void) => void\n  removeEventListener: (type: 'change', listener: () => void) => void\n}\n\nexport interface NetworkState {\n  /**\n   * The effective bandwidth estimate in megabits per second\n   */\n  downlink: number\n  /**\n   * The maximum downlink speed in megabits per second (experimental)\n   */\n  downlinkMax: number | undefined\n  /**\n   * The effective connection type: 'slow-2g', '2g', '3g', or '4g'\n   */\n  effectiveType: 'slow-2g' | '2g' | '3g' | '4g'\n  /**\n   * The estimated round-trip time in milliseconds\n   */\n  rtt: number\n  /**\n   * Whether the user has enabled data saver mode\n   */\n  saveData: boolean\n  /**\n   * The connection type (experimental)\n   */\n  type: 'bluetooth' | 'cellular' | 'ethernet' | 'none' | 'wifi' | 'wimax' | 'other' | 'unknown' | undefined\n  /**\n   * Whether the Network Information API is supported\n   */\n  isSupported: boolean\n  /**\n   * Whether the connection is considered slow (slow-2g or 2g)\n   */\n  isConnectionSlow: boolean\n  /**\n   * Whether the user is currently online\n   */\n  online: boolean\n}\n\nfunction getNetworkState(): NetworkState {\n  if (typeof window === 'undefined') {\n    return {\n      downlink: 0,\n      downlinkMax: undefined,\n      effectiveType: '4g',\n      rtt: 0,\n      saveData: false,\n      type: undefined,\n      isSupported: false,\n      isConnectionSlow: false,\n      online: true,\n    }\n  }\n\n  const nav = navigator as NavigatorWithConnection\n  const connection = nav.connection\n\n  if (!connection) {\n    return {\n      downlink: 0,\n      downlinkMax: undefined,\n      effectiveType: '4g',\n      rtt: 0,\n      saveData: false,\n      type: undefined,\n      isSupported: false,\n      isConnectionSlow: false,\n      online: window.navigator.onLine,\n    }\n  }\n\n  const effectiveType = connection.effectiveType\n  const isConnectionSlow = effectiveType === 'slow-2g' || effectiveType === '2g'\n\n  return {\n    downlink: connection.downlink,\n    downlinkMax: connection.downlinkMax,\n    effectiveType,\n    rtt: connection.rtt,\n    saveData: connection.saveData,\n    type: connection.type,\n    isSupported: true,\n    isConnectionSlow,\n    online: window.navigator.onLine,\n  }\n}\n\nexport function useNetwork(): NetworkState {\n  const [networkState, setNetworkState] = React.useState<NetworkState>(getNetworkState)\n\n  React.useEffect(() => {\n    if (typeof window === 'undefined') {\n      return\n    }\n\n    const nav = navigator as NavigatorWithConnection\n    const connection = nav.connection\n\n    const updateNetworkState = () => {\n      setNetworkState(getNetworkState())\n    }\n\n    if (connection) {\n      connection.addEventListener('change', updateNetworkState)\n    }\n\n    window.addEventListener('online', updateNetworkState)\n    window.addEventListener('offline', updateNetworkState)\n\n    return () => {\n      if (connection) {\n        connection.removeEventListener('change', updateNetworkState)\n      }\n      window.removeEventListener('online', updateNetworkState)\n      window.removeEventListener('offline', updateNetworkState)\n    }\n  }, [])\n\n  return networkState\n}\n",
      "type": "registry:hook",
      "target": "hookas/use-network.ts"
    }
  ],
  "type": "registry:hook"
}