useCommandK
Register a document-level Command+K or Ctrl+K keyboard shortcut.
Signature
A document-level keydown listener for ⌘K and Ctrl+K that calls preventDefault and then your handler.
function useCommandK(onOpen: () => void): void;Usage
import { useState } from "react";
import { CommandPalette, useCommandK } from "@solarius/onset";
import type { CommandPaletteProps } from "@solarius/onset";
function AppShell({
groups,
onRun,
}: Pick<CommandPaletteProps, "groups" | "onRun">) {
const [open, setOpen] = useState(false);
useCommandK(() => setOpen(true));
return (
<CommandPalette
open={open}
onClose={() => setOpen(false)}
groups={groups}
onRun={(command) => {
setOpen(false);
onRun(command);
}}
/>
);
}