本文へ移動
cccskills
無料GitHub で公開

tanstack-hotkeys

Guide for implementing keyboard shortcuts in React using @tanstack/react-hotkeys. Use when building hotkey/shortcut features, registering keyboard shortcuts, handling key sequences, recording custom shortcuts, tracking held keys, or formatting hotkeys for display in React applications.

インストール方法を見る

含まれるファイル(2)

  • SKILL.md5.1 KB
  • references/react-api.md7.3 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

TanStack Hotkeys (React)

Type-safe keyboard shortcut management for React. Package: @tanstack/react-hotkeys.

All framework packages re-export everything from @tanstack/hotkeys core — no separate install needed.

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, Control on Windows/Linux.

Core Hooks

useHotkey(hotkey, callback, options?)

Primary hook. Accepts string ('Mod+S') or RawHotkey object ({ key: 'S', mod: true }).

Callback receives (event: KeyboardEvent, context: { hotkey, parsedHotkey }).

Auto-syncs callback every render (no stale closures). Auto-cleans up on unmount.

// String form
useHotkey('Mod+S', () => save())

// Object form
useHotkey({ key: 'S', mod: true }, () => save())

// Conditional
useHotkey('Escape', () => onClose(), { enabled: isOpen })

// Scoped to element (must be focusable — add tabIndex)
const ref = useRef<HTMLDivElement>(null)
useHotkey('Escape', () => close(), { target: ref })

Default options:

OptionDefaultNotes
enabledtrue
preventDefaulttrueOverrides browser defaults like Cmd+S
stopPropagationtrue
eventType'keydown'Also supports 'keyup'
requireResetfalseWhen true, fires once until all keys released
ignoreInputssmartfalse for Ctrl/Meta combos & Escape; true for single keys & Shift/Alt combos
targetdocumentAccepts DOM element, window, or React ref
conflictBehavior'warn''error', 'replace', 'allow'

useHotkeySequence(sequence, callback, options?)

Vim-style multi-key sequences. Keys pressed in order within timeout.

useHotkeySequence(['G', 'G'], () => scrollToTop())
useHotkeySequence(['D', 'I', 'W'], () => deleteInnerWord(), { timeout: 500 })

// With modifiers
useHotkeySequence(['Mod+K', 'Mod+C'], () => commentSelection())

Options: timeout (default 1000ms), enabled (default true).

Overlapping prefixes work — manager tracks each independently.

useHotkeyRecorder(options)

Record custom shortcuts. Returns { isRecording, recordedHotkey, startRecording, stopRecording, cancelRecording }.

  • Escape cancels recording
  • Backspace/Delete clears recorded hotkey
  • Auto-converts to portable Mod format (Meta+S becomes Mod+S)
const recorder = useHotkeyRecorder({
  onRecord: (hotkey) => setShortcut(hotkey),
  onCancel: () => console.log('cancelled'),
  onClear: () => console.log('cleared'),
})

Key State Tracking

// All held keys
const heldKeys = useHeldKeys() // string[]

// Single key check (optimized — only re-renders when this key changes)
const isShiftHeld = useKeyHold('Shift') // boolean

// Key-to-code mapping (distinguish left/right modifiers)
const codes = useHeldKeyCodes() // Record<string, string>

Display Formatting

import { formatForDisplay, formatWithLabels } from '@tanstack/react-hotkeys'

// Platform-aware symbols
formatForDisplay('Mod+S')        // Mac: "⌘S" | Windows: "Ctrl+S"
formatForDisplay('Mod+Shift+Z')  // Mac: "⇧⌘Z" | Windows: "Ctrl+Shift+Z"

// Text labels
formatWithLabels('Mod+S')        // Mac: "Cmd+S" | Windows: "Ctrl+S"

Use in UI:

<button>Save <kbd>{formatForDisplay('Mod+S')}</kbd></button>

HotkeysProvider

Set global defaults for all hooks. Per-hook options override.

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

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

Devtools

npm install @tanstack/react-devtools @tanstack/react-hotkeys-devtools
import { TanStackDevtools } from '@tanstack/react-devtools'
import { hotkeysDevtoolsPlugin } from '@tanstack/react-hotkeys-devtools'

<TanStackDevtools plugins={[hotkeysDevtoolsPlugin()]} />

Auto-excluded from production builds. Use @tanstack/react-hotkeys-devtools/production import to include in prod.

Key Patterns

  • Scoped hotkeys: Pass target: ref + ensure element has tabIndex
  • Conditional: Use enabled option tied to state
  • Multiple hotkeys: Each useHotkey call is independent
  • Shortcut settings UI: Combine useHotkeyRecorder + useHotkey with dynamic bindings + formatForDisplay
  • Hold-to-reveal UI: Use useKeyHold to conditionally render elements
  • Shortcut hints overlay: Show overlay when modifier held via useKeyHold

API Reference

For complete API details including all interfaces, types, utility functions, and core classes, see references/react-api.md.

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

Browser automation CLI for AI agents. Use when the user needs to interact with websites, including navigating pages, filling forms, clicking buttons, taking screenshots, extracting data, testing web apps, or automating any browser task. Triggers include requests to "open a website", "fill out a form", "click a button", "take a screenshot", "scrape data from a page", "test this web app", "login to a site", "automate browser actions", or any task requiring programmatic web interaction.

日本語の概要は準備中です。原文の説明を表示しています。

fellipeutaka/denji62026年8月3日 更新

Set up and optimize repositories for AI coding agents. Creates minimal AGENTS.md, CLAUDE.md symlink, docs/REQUIREMENTS.md, docs/BUSINESS-RULES.md, feedback loops, and deterministic enforcement (Claude Code hooks, OpenCode plugins). Use when user wants to make a repo AI-friendly, set up AGENTS.md/CLAUDE.md, document requirements/business rules for AI, add pre-commit hooks for AI workflows, or optimize codebase structure for coding agents.

日本語の概要は準備中です。原文の説明を表示しています。

fellipeutaka/denji62026年8月3日 更新

bun

無料

Bun runtime, package manager, bundler, and test runner. Use when running scripts with bun, managing packages, serving HTTP with Bun.serve, querying databases with Bun.sql/bun:sqlite/Bun.redis, shell scripting with $, using S3/file I/O, writing tests with bun:test, bundling or compiling to executable, or using any Bun-specific API (spawn, glob, semver, FFI, workers, plugins, HTMLRewriter).

日本語の概要は準備中です。原文の説明を表示しています。

fellipeutaka/denji62026年8月3日 更新

Write clean, readable, and maintainable code following principles from Robert C. Martin's "Clean Code" and Object Calisthenics. Use when writing, reviewing, or refactoring code to improve naming, function design, formatting, error handling, and class structure. Includes code smell detection and refactoring guidance.

日本語の概要は準備中です。原文の説明を表示しています。

fellipeutaka/denji62026年8月3日 更新

Create high-quality git commits: review/stage intended changes, split into logical commits, and write clear commit messages (including Conventional Commits). Use when the user asks to commit, craft a commit message, stage changes, or split work into multiple commits.

日本語の概要は準備中です。原文の説明を表示しています。

fellipeutaka/denji62026年8月3日 更新

denji

無料

Manage SVG icons as framework components using Denji CLI. Use when the user needs to add, remove, list, export, import, or manage SVG icons in React, Preact, Solid, Qwik, Vue, or Svelte projects. Triggers include requests to "add an icon", "set up icons", "manage SVG icons", "remove an icon", "list icons", "export icons", "import icons", "dry-run icon add", or any task involving Iconify icons as framework components.

日本語の概要は準備中です。原文の説明を表示しています。

fellipeutaka/denji62026年8月3日 更新

fellipeutaka のスキルをすべて見る

このスキルの問題を報告する