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

Function App

examples/preact/useHotkeySequenceRecorder/src/index.tsx:67–291  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

65]
66
67function App() {
68 const [shortcuts, setShortcuts] = React.useState<Array<Shortcut>>(
69 () => INITIAL_SHORTCUTS,
70 )
71
72 // Track which shortcut is being edited
73 const [editingId, setEditingId] = React.useState<string | null>(null)
74 const [draftName, setDraftName] = React.useState('')
75 const [draftDescription, setDraftDescription] = React.useState('')
76
77 const recorder = useHotkeySequenceRecorder({
78 onRecord: (sequence: HotkeySequence) => {
79 if (editingId) {
80 setShortcuts((prev) =>
81 prev.map((s) =>
82 s.id === editingId
83 ? {
84 ...s,
85 sequence,
86 name: draftName,
87 description: draftDescription,
88 }
89 : s,
90 ),
91 )
92 setEditingId(null)
93 }
94 },
95 onCancel: () => {
96 // If this was a brand-new shortcut with no sequence yet, remove it
97 if (editingId) {
98 setShortcuts((prev) => {
99 const shortcut = prev.find((s) => s.id === editingId)
100 if (shortcut && shortcut.sequence.length === 0) {
101 return prev.filter((s) => s.id !== editingId)
102 }
103 return prev
104 })
105 }
106 setEditingId(null)
107 },
108 onClear: () => {
109 if (editingId) {
110 setShortcuts((prev) =>
111 prev.map((s) =>
112 s.id === editingId
113 ? {
114 ...s,
115 sequence: [],
116 name: draftName,
117 description: draftDescription,
118 }
119 : s,
120 ),
121 )
122 setEditingId(null)
123 }
124 },

Callers

nothing calls this directly

Calls 5

useHotkeySequencesFunction · 0.90
formatForDisplayFunction · 0.85
handleEditFunction · 0.70
handleDeleteFunction · 0.70

Tested by

no test coverage detected