-
-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include componentDidUpdate cycle to refresh the updated keysets #24
Comments
Is there another work around for this? When a component with HotKey updates the list of keyName dynamically, the new keyNames doesn't work |
Solving this problem is not easy. I need some time. |
A workaround I use is to use an HOC to force replace the whole Demo code: import React, { FC, ReactNode, useEffect, useState } from 'react'
import Hotkeys from 'react-hot-keys'
interface HotKeyHocProps {
children: ReactNode
keyName?: string
onKeyUp?: (keyName: string, e: KeyboardEvent, handle: any) => void
onKeyDown?: (keyName: string, e: KeyboardEvent, handle: any) => void
}
const HotKeyHoc: FC<HotKeyHocProps> = ({
children,
keyName,
onKeyUp,
onKeyDown,
}) => {
const [tempUpdate, setTempUpdate] = useState(false)
useEffect(() => {
if (keyName && !tempUpdate) {
setTempUpdate(true) // NOTE: Let conditional render statement remove the original <Hotkeys />
setTimeout(() => setTempUpdate(false)) // NOTE: Re-render the whole <Hotkeys /> again after a short time
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [keyName])
return keyName && !tempUpdate ? ( // NOTE: Setup the conditional render statement here
<Hotkeys keyName={keyName} onKeyUp={onKeyUp} onKeyDown={onKeyDown}>
{children}
</Hotkeys>
) : (
<>{children}</>
)
}
export default HotKeyHoc
|
The issue should be resolved in the sourcecode pretty easily inside the code if you just implement ComponentDidUpdate... |
Can you add the componentDidUpdate cycle to refresh the update keyset combination?
I think the following code block will fix the problem.
The text was updated successfully, but these errors were encountered: