@@ -67,13 +67,26 @@ export function useHotkey(
6767) : void {
6868 const { enabled = true , ...hotkeyOptions } = options
6969
70+ // Extract options for stable dependencies
71+ const {
72+ preventDefault,
73+ stopPropagation,
74+ platform,
75+ eventType,
76+ requireReset,
77+ } = hotkeyOptions
78+
7079 // Use refs to keep callback and hotkey stable across renders
7180 const callbackRef = useRef ( callback )
7281 callbackRef . current = callback
7382
7483 const hotkeyRef = useRef ( hotkey )
7584 hotkeyRef . current = hotkey
7685
86+ // Serialize hotkey for dependency comparison
87+ const hotkeyKey =
88+ typeof hotkey === 'string' ? hotkey : JSON . stringify ( hotkey )
89+
7790 useEffect ( ( ) => {
7891 if ( ! enabled ) {
7992 return
@@ -86,25 +99,33 @@ export function useHotkey(
8699 : formatParsedHotkey ( hotkeyValue )
87100
88101 const manager = getHotkeyManager ( )
102+
103+ // Build options object, only including defined values to avoid
104+ // overwriting manager defaults with undefined
105+ const registerOptions : HotkeyOptions = { enabled : true }
106+ if ( preventDefault !== undefined )
107+ registerOptions . preventDefault = preventDefault
108+ if ( stopPropagation !== undefined )
109+ registerOptions . stopPropagation = stopPropagation
110+ if ( platform !== undefined ) registerOptions . platform = platform
111+ if ( eventType !== undefined ) registerOptions . eventType = eventType
112+ if ( requireReset !== undefined ) registerOptions . requireReset = requireReset
113+
89114 const unregister = manager . register (
90115 hotkeyString ,
91116 ( event , context ) => callbackRef . current ( event , context ) ,
92- {
93- ...hotkeyOptions ,
94- enabled : true ,
95- } ,
117+ registerOptions ,
96118 )
97119
98120 return unregister
99121 } , [
100122 enabled ,
101- hotkeyOptions . preventDefault ,
102- hotkeyOptions . stopPropagation ,
103- hotkeyOptions . platform ,
104- hotkeyOptions . eventType ,
105- hotkeyOptions . requireReset ,
106- // Re-register if hotkey changes (serialize for comparison)
107- typeof hotkey === 'string' ? hotkey : JSON . stringify ( hotkey ) ,
123+ preventDefault ,
124+ stopPropagation ,
125+ platform ,
126+ eventType ,
127+ requireReset ,
128+ hotkeyKey ,
108129 ] )
109130}
110131
0 commit comments