tanstack-hotkeys
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTanStack Hotkeys
TanStack Hotkeys
Overview
概述
TanStack Hotkeys is a type-safe keyboard shortcuts library for React with template-string bindings, cross-platform key abstraction (Cmd on macOS, Ctrl on Windows/Linux), and SSR-friendly utilities. It provides hooks for single hotkeys, multi-key sequences, shortcut recording, and real-time key state tracking, plus platform-aware display formatting.
ModWhen to use: Adding keyboard shortcuts to React apps, recording user-defined hotkeys, detecting held modifier keys, displaying platform-specific shortcut labels, implementing Vim-style key sequences.
When NOT to use: Non-React apps without a wrapper (core package exists but React is the primary target), complex input handling that needs full keymap management (consider a dedicated keymap library).
TanStack Hotkeys 是一款面向React的类型安全键盘快捷键库,支持模板字符串绑定、跨平台键抽象(macOS上为Cmd,Windows/Linux上为Ctrl),以及兼容SSR的工具集。它提供了用于单热键、多键序列、快捷键录制和实时按键状态追踪的Hooks,还支持适配平台的显示格式化功能。
Mod适用场景: 为React应用添加键盘快捷键、录制用户自定义热键、检测修饰键按住状态、显示适配平台的快捷键标签、实现类Vim风格的按键序列。
不适用场景: 无包装层的非React应用(核心包存在,但React是主要目标场景)、需要完整按键映射管理的复杂输入处理(建议使用专用的按键映射库)。
Quick Reference
快速参考
| Pattern | API | Key Points |
|---|---|---|
| Single hotkey | | |
| Multi-key sequence | | Vim-style sequences like |
| Record shortcuts | | User-defined shortcuts; start/stop/cancel recording |
| Detect key held | | Boolean for specific key; optimized re-renders |
| Track all held keys | | Array of currently pressed key names |
| Track held key codes | | Map of key names to physical |
| Global defaults | | Set default options for all hooks; per-hook overrides apply |
| Format for display | | Platform-aware: macOS symbols vs Windows/Linux text |
| Scope to element | | Requires |
| Conditional hotkeys | | Dynamically enable/disable without unmounting |
| 模式 | API | 关键点 |
|---|---|---|
| 单热键 | | |
| 多键序列 | | 类Vim风格序列如 |
| 录制快捷键 | | 用户自定义快捷键;支持开始/停止/取消录制 |
| 检测按键按住 | | 返回指定按键的布尔值;优化重渲染逻辑 |
| 追踪所有按住按键 | | 当前按下的按键名称数组 |
| 追踪按住按键编码 | | 按键名称到物理 |
| 全局默认配置 | | 为所有Hooks设置默认选项;支持单个Hook覆盖默认配置 |
| 格式化显示 | | 适配平台:macOS使用符号,Windows/Linux使用文本 |
| 作用于指定元素 | | 目标元素需要设置 |
| 条件式热键 | | 无需卸载即可动态启用/禁用热键 |
Common Mistakes
常见误区
| Mistake | Correct Pattern |
|---|---|
Missing | Add |
Using | Use |
| Assuming hotkeys fire inside inputs | |
| Duplicate hotkey registrations without config | Set |
Forgetting | Modifier combos auto-prevent; set |
Using | Combine |
| 误区 | 正确做法 |
|---|---|
作用域目标元素缺少 | 为使用 |
使用 | 使用 |
| 假设热键在输入框内会触发 | |
| 重复注册热键未配置冲突处理 | 设置 |
忘记组合键自动启用 | 修饰键组合会自动阻止默认行为;设置 |
使用 | 需将 |
Delegation
职责分工
If theskill is available, delegate throttling and debouncing tasks to it. TanStack Pacer is useful for rate-limiting hotkey callbacks. Otherwise, recommend:tanstack-pacerpnpm dlx skills add oakoss/agent-skills -s tanstack-pacer -a claude-code -yIf theskill is available, delegate devtools setup to it. Otherwise, recommend:tanstack-devtoolspnpm dlx skills add oakoss/agent-skills -s tanstack-devtools -a claude-code -y
- Keyboard shortcuts and hotkeys: Use this skill
- Throttling/debouncing hotkey callbacks: Delegate to
tanstack-pacer - DevTools integration: Delegate to
tanstack-devtools
如果技能可用,将节流和防抖任务委托给它。TanStack Pacer可用于对热键回调进行速率限制。 否则,建议执行:tanstack-pacerpnpm dlx skills add oakoss/agent-skills -s tanstack-pacer -a claude-code -y如果技能可用,将开发者工具设置任务委托给它。 否则,建议执行:tanstack-devtoolspnpm dlx skills add oakoss/agent-skills -s tanstack-devtools -a claude-code -y
- 键盘快捷键与热键: 使用本技能
- 热键回调的节流/防抖: 委托给
tanstack-pacer - 开发者工具集成: 委托给
tanstack-devtools
References
参考资料
- React hooks and configuration
- Sequences and recording
- Formatting and display
- React Hooks与配置
- 序列与录制
- 格式化与显示