From dc4a38f391bd30df50c9da754b7ce5e2ae55d4d5 Mon Sep 17 00:00:00 2001 From: Tom Butcher Date: Sat, 1 Aug 2026 14:13:24 +0100 Subject: [PATCH] Refactor KeyboardShortcut component to simplify state management - Removed unused state for tracking pressed keys, streamlining the key handling logic. - Eliminated the sync function for pressed keys, enhancing performance and reducing complexity. - Maintained existing functionality while improving the overall structure of the component. --- src/components/Dashboard/common/KeyboardShortcut.jsx | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/components/Dashboard/common/KeyboardShortcut.jsx b/src/components/Dashboard/common/KeyboardShortcut.jsx index 9afd4d3..9913d3a 100644 --- a/src/components/Dashboard/common/KeyboardShortcut.jsx +++ b/src/components/Dashboard/common/KeyboardShortcut.jsx @@ -1,4 +1,4 @@ -import { useEffect, useRef, cloneElement, useMemo, useState } from 'react' +import { useEffect, useRef, cloneElement, useMemo } from 'react' import PropTypes from 'prop-types' import { Popover, Typography } from 'antd' @@ -50,18 +50,12 @@ const KeyboardShortcut = ({ const childRef = useRef() const pressedKeysRef = useRef(new Set()) const shortcutKeys = useMemo(() => parseShortcut(shortcut), [shortcut]) - const [pressedKeys, setPressedKeys] = useState([]) useEffect(() => { - const syncPressedKeys = () => { - setPressedKeys([...pressedKeysRef.current]) - } - const handleKeyDown = (event) => { const key = getPressedKey(event) if (key) { pressedKeysRef.current.add(key) - syncPressedKeys() } if (log) { @@ -83,7 +77,6 @@ const KeyboardShortcut = ({ const key = getPressedKey(event) if (key) { pressedKeysRef.current.delete(key) - syncPressedKeys() } }