Skip to Content
Headless SDKHooksDevice & Context

Device & Context Hooks

Hooks for reading device metadata, safe areas, and keyboard state.

useDeviceInfo()

Read device, browser, and OS metadata. Values are set once on mount and rarely change.

const { device, browser, os } = useDeviceInfo() if (device.isMobile) { // mobile-specific layout }

os

FieldTypeDescription
namestringOperating system name
timezonestringOS timezone

device

FieldTypeDescription
typestringDevice type ("desktop", "mobile", "tablet")
isMobilebooleanTrue on mobile devices
isTabletbooleanTrue on tablets
screenWidthnumberScreen width in pixels
screenHeightnumberScreen height in pixels
viewportWidthnumberViewport width in pixels
viewportHeightnumberViewport height in pixels
colorDepthnumberDisplay color depth
pixelRationumberDevice pixel ratio

browser

FieldTypeDescription
namestringBrowser name
versionstringBrowser version
userAgentstringFull user agent string
cookieEnabledbooleanWhether cookies are enabled
onlinebooleanWhether the browser is online
languagestringBrowser language

useSafeArea()

Returns CSS safe area insets in pixels. Useful for positioning fixed elements on notched devices. Updates on resize.

const { bottom } = useSafeArea() return <div style={{ position: 'fixed', bottom: 0, paddingBottom: bottom }} />
PropertyTypeDescription
topnumberTop inset in pixels
rightnumberRight inset in pixels
bottomnumberBottom inset in pixels
leftnumberLeft inset in pixels

useKeyboard()

Detect the virtual keyboard on mobile devices. Uses the VirtualKeyboard API where available, with a visualViewport fallback for Safari.

const { isOpen, height } = useKeyboard() return <div style={{ paddingBottom: isOpen ? height : 0 }} />
PropertyTypeDescription
isOpenbooleanWhether the virtual keyboard is visible
heightnumberKeyboard height in pixels (0 when closed)
Last updated on