mirror of
https://github.com/streamich/react-use.git
synced 2026-01-18 14:06:52 +00:00
fix: repair useKeyboardJs hook
Fixed the importing of the KeyboardJS library with backward compatibility. Updated how bindings are set to prevent KeyboardJS from calling handlers repeatedly while holding keys.
This commit is contained in:
parent
0fabbcd641
commit
8410bb042f
@ -6,7 +6,7 @@ const useKeyboardJs = (combination: string | string[]) => {
|
||||
const [keyboardJs, setKeyboardJs] = useState<any>(null);
|
||||
|
||||
useMount(() => {
|
||||
import('keyboardjs').then(setKeyboardJs);
|
||||
import('keyboardjs').then(k => setKeyboardJs(k.default || k));
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
@ -16,7 +16,7 @@ const useKeyboardJs = (combination: string | string[]) => {
|
||||
|
||||
const down = event => set([true, event]);
|
||||
const up = event => set([false, event]);
|
||||
keyboardJs.bind(combination, down, up);
|
||||
keyboardJs.bind(combination, down, up, true);
|
||||
|
||||
return () => {
|
||||
keyboardJs.unbind(combination, down, up);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user