Skip to content
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

Passing a falsy value as the hook's first argument unbinds ALL handlers #754

Closed
srmagura opened this issue May 18, 2022 · 2 comments
Closed

Comments

@srmagura
Copy link

CodeSandbox that demonstrates the issue

It happens because of this line in hotkeys-js.

Is the current behavior intentional? Whether intentional or not, I think we need to change it in some way since the current behavior makes it very easy to write a bug. I am happy to help brainstorm and potentially submit a PR.

Workaround

Never pass in a falsy value like empty string or undefined as the first argument of useHotkeys. Instead, you can pass a nearly-impossible combination of keys like '1+2+3+4+5+6+7+8+9'. This effectively disables the hook without resulting in other handlers being unbound. You could probably achieve the same thing using using the hook's enabled option.

@JohannesKlauss
Copy link
Owner

Well the easiest fix would be to fix it in hotkeys-js package. Changing the line above the mentioned one to if (typeof keysInfo === 'undefined') will take care of it. So maybe it is better to raise this issue in the hotkeys-js repo

@srmagura
Copy link
Author

Sounds good. I will submit a PR to them this weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants