Shadcn Hooks

useOs

A hook to detect the current operating system

Loading...

Installation

npx shadcn@latest add @shadcnhooks/use-os

API

export type UseOSReturnValue =
  | 'undetermined'
  | 'macos'
  | 'ios'
  | 'windows'
  | 'android'
  | 'linux'
  | 'chromeos'

export interface UseOsOptions {
  /**
   * Defer browser OS detection until after mount to avoid server/client mismatches.
   * @default true
   */
  getValueInEffect?: boolean
}

/**
 * Detect the current operating system from the browser environment.
 *
 * @param options Hook options.
 * @returns The detected operating system or `undetermined`.
 */
export function getOS(options?: UseOsOptions): UseOSReturnValue

/**
 * Reactively detect the current operating system from `navigator.userAgent`.
 *
 * @param options Hook options.
 * @returns The detected operating system or `undetermined`.
 */
export function useOs(options?: UseOsOptions): UseOSReturnValue

Credits

Last updated on

On this page