Skip to content

Commit

Permalink
Fix the ShortcutProvider usage (#54851)
Browse files Browse the repository at this point in the history
Co-authored-by: Marin Atanasov <8436925+tyxla@users.noreply.github.com>
  • Loading branch information
2 people authored and mikachan committed Sep 29, 2023
1 parent 87c2691 commit 1271ebb
Showing 1 changed file with 3 additions and 3 deletions.
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { useRef } from '@wordpress/element';
import { useState } from '@wordpress/element';

/**
* Internal dependencies
Expand All @@ -20,12 +20,12 @@ const { Provider } = context;
* @return {import('@wordpress/element').WPElement} Component.
*/
export function ShortcutProvider( props ) {
const keyboardShortcuts = useRef( new Set() );
const [ keyboardShortcuts ] = useState( () => new Set() );

function onKeyDown( event ) {
if ( props.onKeyDown ) props.onKeyDown( event );

for ( const keyboardShortcut of keyboardShortcuts.current ) {
for ( const keyboardShortcut of keyboardShortcuts ) {
keyboardShortcut( event );
}
}
Expand Down

0 comments on commit 1271ebb

Please sign in to comment.