Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

tanstack-hotkeys-guide

БесплатноБез исполняемых скриптовНе проверен

TanStack Hotkeys guide for type-safe keyboard shortcuts in React. Use when user asks to "add keyboard shortcuts", "register hotkeys", "handle keyboard…

vcode-shот vcode-sh★ 19 звёзд на GitHub

Об этом скилле

Purpose

TanStack Hotkeys is a type-safe, framework-agnostic library for handling keyboard shortcuts. It provides React hooks for registering hotkeys, multi-key sequences, recording custom shortcuts, tracking key state, and platform-aware display formatting. The library uses event.key as its primary API with event.code fallback for letter/digit keys. Currently in alpha -- API may change.

When NOT to use: For a single shortcut listener, a plain addEventListener('keydown', ...) may suffice. Reach for TanStack Hotkeys when you need multiple shortcuts, cross-platform Mod handling, sequences, recording, or key-state tracking.

Instructions

  • Always use Mod instead of platform-specific Meta or Control for cross-platform shortcuts
  • Import from @tanstack/react-hotkeys for React projects (it re-exports everything from @tanstack/hotkeys)
  • Import from @tanstack/hotkeys only for vanilla JS without React
  • Prefer the string form ('Mod+S') over RawHotkey objects unless the hotkey is dynamic or built programmatically
  • Always add tabIndex={0} to elements used as target refs -- they must be focusable to receive keyboard events
  • When building shortcut customization UIs, combine useHotkeyRecorder with formatForDisplay for recording and display
  • The recorder auto-converts platform keys to portable Mod format -- do not manually convert recorded hotkeys
  • Do NOT combine Mod with Control or Mod with Meta -- these create duplicate modifiers on one platform
  • Avoid Alt+letter shortcuts for cross-platform apps -- macOS produces special characters with Option+letter
  • Avoid Shift+number and Shift+punctuation shortcuts -- results are keyboard-layout-dependent
  • Warn the user that TanStack Hotkeys is in alpha when recommending it for production use
  • Default preventDefault: true and stopPropagation: true are intentional -- override explicitly only when needed
  • Use conflictBehavior: 'allow' for intentional duplicate hotkeys, not to silence bugs

Installation

npm install @tanstack/react-hotkeys

The React package re-exports everything from @tanstack/hotkeys. No separate core install needed. For vanilla JS only, install @tanstack/hotkeys directly.

Optional devtools:

npm install @tanstack/react-devtools @tanstack/react-hotkeys-devtools

Quick Start

import { useHotkey } from '@tanstack/react-hotkeys'

function App() {
  useHotkey('Mod+S', () => saveDocument())
  return <div>Press Cmd+S (Mac) or Ctrl+S (Windows) to save</div>
}

Mod resolves to Meta (Cmd) on macOS and Control on Windows/Linux.

React Hooks Reference

useHotkey(hotkey, callback, options?)

Register a keyboard shortcut. Auto-syncs callback every render (no stale closures). Auto-unregisters on unmount.

useHotkey('Mod+S', (event, { hotkey, parsedHotkey }) => {
  save()
})

Accept a string ('Mod+S') or RawHotkey object ({ key: 'S', mod: true }).

useHotkeySequence(sequence, callback, options?)

Register Vim-style multi-key sequences. Each step can include modifiers.

useHotkeySequence(['G', 'G'], () => scrollToTop())
useHotkeySequence(['Mod+K', 'Mod+C'], () => commentSelection())

Options: { timeout: 1000, enabled: true }.

useHotkeyRecorder(options)

Record custom keyboard shortcuts for settings UIs. Auto-converts to portable Mod format.

const { isRecording, recordedHotkey, startRecording, stopRecording, cancelRecording } =
  useHotkeyRecorder({ onRecord: (hotkey) => setShortcut(hotkey) })

Options: { onRecord, onCancel?, onClear? }. Escape cancels. Backspace/Delete clears.

useHeldKeys()

Return a reactive string[] of currently held key names.

useHeldKeyCodes()

Return a reactive Record<string, string> mapping key names to event.code values.

useKeyHold(key)

Return boolean for a specific key's hold state. Only re-renders when that key changes.

const isShiftHeld = useKeyHold('Shift')

useDefaultHotkeysOptions()

Return the current default options from HotkeysProvider context.

useHotkeysContext()

Return the full hotkeys context value, or null if outside a provider.

HotkeysProvider

Wrap the app to set global default options. Per-hook options override provider defaults.

import { HotkeysProvider } from '@tanstack/react-hotkeys'

<HotkeysProvider defaultOptions={{
  hotkey: { preventDefault: true },
  hotkeySequence: { timeout: 1500 },
  hotkeyRecorder: { onCancel: () => console.log('cancelled') },
}}>
  <App />
</HotkeysProvider>

Hotkey String Format

  • Modifiers: Control, Alt, Shift, Meta
  • Cross-platform: Mod (Cmd on Mac, Ctrl on Windows/Linux)
  • Format: Modifier+Modifier+Key -- e.g., 'Mod+Shift+S'
  • Single keys: 'Escape', 'Enter', 'F1', 'ArrowUp', 'A', '1', '/'
  • RawHotkey alternative: { key: 'S', mod: true, shift: true }
  • Mod+Control and Mod+Meta combinations are NOT allowed (would duplicate
Полный SKILL.md на GitHub

Установить tanstack-hotkeys-guide в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

references/api-reference.mdreferences/patterns.mdreferences/troubleshooting.md

FAQ

Что делает скилл tanstack-hotkeys-guide?

TanStack Hotkeys guide for type-safe keyboard shortcuts in React. Use when user asks to "add keyboard shortcuts", "register hotkeys", "handle keyboard shortcuts in React", "implement key bindings", "use TanStack Hotkeys", "use useHotkey", "add Mod+S shortcut", "create vim-style key sequences", "record keyboard shortcuts", "track held keys", "format hotkey display", "show keyboard shortcut badges", or asks about "@tanstack/react-hotkeys", "useHotkey hook", "useHotkeySequence", "useHotkeyRecorder", "useHeldKeys", "useKeyHold", "HotkeyManager", "formatForDisplay", or "keyboard shortcut customization UI". Covers hotkey registration, multi-key sequences, hotkey recording, key state tracking, platform-aware display formatting, and devtools integration. Do NOT use for react-hotkeys-hook, Mousetrap, use-hotkeys, hotkeys-js, or other keyboard shortcut libraries -- this is specifically for @tanstack/react-hotkeys.

Как установить скилл tanstack-hotkeys-guide?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл tanstack-hotkeys-guide запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить tanstack-hotkeys-guide с