react-hotkeys-hook
react-hotkeys-hook copied to clipboard
`isHotkeyPressed` not working when not using `useHotKeys` anywhere
Seems like isHotKeyPressed
always return false
when useHotKeys
isn't used elsewhere in the app.
Holding shift
and clicking the button does not increment the count: https://codesandbox.io/s/prod-glitter-x5fxiw?file=/src/App.js
Same sandbox, but if I invoke useHotKeys
, holding shift
and clicking the button does increment the count: https://codesandbox.io/s/wizardly-sun-1ns9sz?file=/src/App.js
Seems like when using hotkeys-js
directly, you need to wrap any calls to hotkeys.isPressed
inside hotkeys()
- hence I think the behavior showcased in the codesandbox above is expected.
However, seems like useHotKeys
does have some side effects, which caught me off guard, thinking something was wrong.
I'd imagine the number of people using this library without using useHotKeys
to be quite small, as at this point you're better off using hotkeys-js
directly.
This seems to be related to #765
Starting at version 4 we will drop the hotkeys-js package and rely on our own solution. isHotkeysPressed
will then work independently from the hook. Although we haven't implemented that feature yet, I am confident that we will have it working as we intended it.
Version 4 will hopefully have its first release candidate in the next few weeks.
This is fixed with version 4