using the react pacakge: unbind the key when the component is unmounted #60
ofirgeller
started this conversation in
Ideas
Replies: 1 comment
-
|
would be even better if children would shadow the bindings of their parents. so that when a menu appears it binds the escape key but when it is gone the main view captures it and does something else. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I think the react API should maybe look like this:
import { useEffect } from "react";
import {
bindKey,
bindKeyCombo,
unbindKey,
unbindKeyCombo,
} from "@rwh/keystrokes";
export const useBindKey = (targetKey: string, handler: () => void) => {
useEffect(() => {
bindKey(targetKey, handler);
}, [targetKey, handler]);
};
export const useBindKeyCombo = (targetKey: string, handler: () => void) => {
useEffect(() => {
bindKeyCombo(targetKey, handler);
}, [targetKey, handler]);
};
just getting a Boolean is not as helpful and it makes sense that the binding goes away when the component dismounts.
thoughts?
Beta Was this translation helpful? Give feedback.
All reactions