react-hotkeys-hook icon indicating copy to clipboard operation
react-hotkeys-hook copied to clipboard

`isHotkeyPressed` not working when not using `useHotKeys` anywhere

Open nddery opened this issue 2 years ago • 2 comments

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

nddery avatar Jun 10 '22 16:06 nddery

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.

nddery avatar Jun 10 '22 21:06 nddery

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.

JohannesKlauss avatar Jun 13 '22 07:06 JohannesKlauss

This is fixed with version 4

JohannesKlauss avatar Nov 04 '22 08:11 JohannesKlauss