Skip to main content
/
/
/
useHotkey()

useHotkey()

import useHotkey from "@intility/bifrost-react/hooks/useHotkey";

Listen to platform-independent hotkeys.

  • key (string) - the key to listen to, a single lowercase character (like "k" or "s")
  • callback (function) - will be called when user presses ⌘ + key on macOS, or Ctrl + key on win/linux
  • returns an object with hotkeyText (string) which will be "⌘ + key" or "Ctrl + key" depending on platform
// listen to Ctrl/⌘ + K keypress const { hotkeyText } = useHotkey("k", () => { // focus search input, for example inputRef.current?.focus(); }); // hotkeyText will be "⌘ + K" or "Ctrl + K"
// listen to Ctrl/⌘ + K keypress const { hotkeyText } = useHotkey("k", () => { // focus search input, for example inputRef.current?.focus(); }); // hotkeyText will be "⌘ + K" or "Ctrl + K"