BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/shadcn-hooks/use-os

use-os

shadcn-hooks/use-os
FreeHook

A hook to detect the current operating system

Install it

npx shadcn@latest add https://shadcn-hooks.com/r/use-os.json

Source

registry/hooks/use-os.tsshadcn-hooks.com/r/use-os.json
1import { useEffect, useState } from 'react'
2
3export type UseOSReturnValue =
4 | 'undetermined'
5 | 'macos'
6 | 'ios'
7 | 'windows'
8 | 'android'
9 | 'linux'
10 | 'chromeos'
11
12export interface UseOsOptions {
13 /**
14 * Defer browser OS detection until after mount to avoid server/client mismatches.
15 * @default true
16 */
17 getValueInEffect?: boolean
18}
19
20interface NavigatorWithUserAgentData extends Navigator {
21 userAgentData?: {
22 platform?: string
23 }
24}
25
26function getPlatform(): string {
27 if (typeof navigator === 'undefined') {
28 return ''
29 }
30
31 const nav = navigator as NavigatorWithUserAgentData
32
33 return (nav.userAgentData?.platform ?? navigator.platform ?? '').toLowerCase()
34}
35
36function getUserAgent(): string {
37 if (typeof navigator === 'undefined') {
38 return ''
39 }
40
41 return navigator.userAgent.toLowerCase()
42}
43
44/**
45 * Detect the current operating system from the browser environment.
46 *
47 * @param options Hook options.
48 * @returns The detected operating system or `undetermined`.
49 */
50export function getOS(options: UseOsOptions = {}): UseOSReturnValue {
51 const { getValueInEffect = true } = options
52
53 if (getValueInEffect || typeof navigator === 'undefined') {
54 return 'undetermined'
55 }
56
57 const platform = getPlatform()
58 const userAgent = getUserAgent()
59 const maxTouchPoints = navigator.maxTouchPoints ?? 0
60
61 if (userAgent.includes('android')) {
62 return 'android'
63 }
64
65 if (
66 /iphone|ipad|ipod/.test(userAgent) ||
67 (platform === 'macintel' && maxTouchPoints > 1)
68 ) {
69 return 'ios'
70 }
71
72 if (userAgent.includes('cros')) {
73 return 'chromeos'
74 }
75
76 if (platform.includes('win') || userAgent.includes('win')) {
77 return 'windows'
78 }
79
80 if (platform.includes('mac') || userAgent.includes('mac')) {
81 return 'macos'
82 }
83
84 if (platform.includes('linux') || userAgent.includes('linux')) {
85 return 'linux'
86 }
87
88 return 'undetermined'
89}
90
91/**
92 * Reactively detect the current operating system from `navigator.userAgent`.
93 *
94 * @param options Hook options.
95 * @returns The detected operating system or `undetermined`.
96 */
97export function useOs(options: UseOsOptions = {}): UseOSReturnValue {
98 const { getValueInEffect = true } = options
99 const [os, setOs] = useState<UseOSReturnValue>(() =>
100 getOS({ getValueInEffect }),
101 )
102
103 useEffect(() => {
104 setOs(getOS({ getValueInEffect: false }))
105 }, [getValueInEffect])
106
107 return os
108}

Files it writes

  • registry/hooks/use-os.ts

Facts

Registry
shadcn-hooks
Type
registry:hook
Access
Free
Files written
1
Licence
the repository states none
In the index
at or before 2026-08-10
Last confirmed
today

Go to the source

shadcn-hooks.com Debbl/shadcn-hooks on GitHub Raw registry item This item as JSON

More from shadcn-hooks

All 58 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
use-active-elementuse-active-elementshadcn-hooksHooksFreeno deps
use-batteryuse-batteryshadcn-hooksHooksFreeno deps
use-booleanuse-booleanshadcn-hooksHooksFreeno deps
use-click-any-whereuse-click-any-whereshadcn-hooksHooksFreeno deps
use-click-awayuse-click-awayshadcn-hooksHooksFreeno deps
use-clipboarduse-clipboardshadcn-hooksHooksFreeno deps
use-controllable-valueuse-controllable-valueshadcn-hooksHooksFree1 dep
use-counteruse-countershadcn-hooksHooksFreeno deps

Also from Kynth Studios

Built for the same person as BlockDex

SkillWorks

Claude Code skills and plugins, scored

skillworks.kynth.studio

RuleStack

AGENTS.md gallery and agent-config comparison

rulestack.kynth.studio

ToolDrift

What the AI coding tools changed last night

tooldrift.kynth.studio

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex