MCPcopy Create free account
hub / github.com/TanStack/hotkeys / App

Function App

examples/react/useHotkeySequences/src/index.tsx:14–328  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12import './index.css'
13
14function App() {
15 const [lastSequence, setLastSequence] = React.useState<string | null>(null)
16 const [history, setHistory] = React.useState<Array<string>>([])
17 const [helloSequenceEnabled, setHelloSequenceEnabled] = React.useState(true)
18
19 const addToHistory = (action: string) => {
20 setLastSequence(action)
21 setHistory((h) => [...h.slice(-9), action])
22 }
23
24 useHotkeySequences([
25 {
26 sequence: ['G', 'G'],
27 callback: () => addToHistory('gg → Go to top'),
28 options: {
29 meta: {
30 name: 'Go to top',
31 description: 'Scroll to the beginning of the document',
32 },
33 },
34 },
35 {
36 sequence: ['Shift+G'],
37 callback: () => addToHistory('G → Go to bottom'),
38 options: {
39 meta: {
40 name: 'Go to bottom',
41 description: 'Scroll to the end of the document',
42 },
43 },
44 },
45 {
46 sequence: ['D', 'D'],
47 callback: () => addToHistory('dd → Delete line'),
48 options: {
49 meta: { name: 'Delete line', description: 'Delete the current line' },
50 },
51 },
52 {
53 sequence: ['Y', 'Y'],
54 callback: () => addToHistory('yy → Yank (copy) line'),
55 options: {
56 meta: {
57 name: 'Yank line',
58 description: 'Copy the current line to clipboard',
59 },
60 },
61 },
62 {
63 sequence: ['D', 'W'],
64 callback: () => addToHistory('dw → Delete word'),
65 options: {
66 meta: {
67 name: 'Delete word',
68 description: 'Delete from cursor to end of word',
69 },
70 },
71 },

Callers

nothing calls this directly

Calls 3

useHotkeySequencesFunction · 0.90
useHotkeyFunction · 0.90
addToHistoryFunction · 0.70

Tested by

no test coverage detected