useApplePlatform
Whether the visitor is on an Apple platform, so a shortcut hint can read ⌘K there and Ctrl K elsewhere.
useApplePlatform tells you whether the visitor is on macOS, iOS or iPadOS. It is the same check useHotkey runs to decide that mod means ⌘ there and Ctrl everywhere else, so a hint you label with it always matches the key that actually fires.
import { useApplePlatform } from '@42-central/ui-react';
const apple = useApplePlatform();
<Kbd>{apple ? '⌘' : 'Ctrl'}</Kbd>To label a whole hotkey string, you don't need it directly: <Kbd hotkey="mod+k" /> draws [⌘] [K] or [Ctrl] [K] for you, one cap per key, and hotkeyKeys and formatHotkey (pass them this hook's value while rendering) give you the same keys as text.
Usage
Search the docs
Not an Apple platform
Code
const apple = useApplePlatform();
<Kbd>{apple ? '⌘' : 'Ctrl'}</Kbd>
<Kbd>K</Kbd>API
function useApplePlatform(): boolean
function isApplePlatform(): booleanuseApplePlatform takes no arguments and returns true on an Apple platform.
isApplePlatform is the plain function underneath, for code outside render: an event handler, or a module that formats a shortcut string. It reads navigator.userAgentData.platform where the browser has it and falls back to navigator.platform, and returns false when there is no navigator (on the server).
SSR
The hook returns false on the server and during the hydration render, then the real value right after. A Mac visitor therefore sees Ctrl for one frame on a server-rendered page. That frame is what keeps the server HTML and the hydrated markup identical. Calling isApplePlatform() directly during render would skip that step and cause a hydration mismatch on every Mac, so use the hook in components.