shortcut.tsx 540 B

123456789101112131415161718
  1. "use client";
  2. import { useSyncExternalStore } from "react";
  3. const noSubscribe = () => () => {};
  4. const platformShortcut = () =>
  5. /Mac|iPhone|iPad/.test(navigator.platform || navigator.userAgent)
  6. ? "⌘K"
  7. : "Ctrl K";
  8. /** The command palette's shortcut as this platform writes it (⌘K until hydrated). */
  9. export const useShortcut = () =>
  10. useSyncExternalStore(noSubscribe, platformShortcut, () => "⌘K");
  11. /** The same label, for server-rendered places like the footer. */
  12. export function Shortcut() {
  13. return useShortcut();
  14. }