UNPKG

@tanstack/react-hotkeys

Version:

React adapter for TanStack Hotkeys

21 lines (18 loc) • 744 B
'use client'; import { useDefaultHotkeysOptions } from "./HotkeysProvider.js"; import { detectPlatform } from "@tanstack/hotkeys"; import { useSyncExternalStore } from "react"; import { getServerPlatformSnapshot } from "@tanstack/hotkeys/adapter"; //#region src/_usePlatform.ts const subscribe = () => () => {}; /** * The provider's platform, or the detected one. Without a provider platform, * server rendering and hydration use 'linux', then the client re-renders * with the detected platform. */ function usePlatform() { const platform = useDefaultHotkeysOptions().platform; return useSyncExternalStore(subscribe, () => platform ?? detectPlatform(), () => platform ?? getServerPlatformSnapshot()); } //#endregion export { usePlatform };