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:
Robert Hurst 2020-06-04 22:29:17 -07:00
parent 0fabbcd641
commit 8410bb042f

View File

@ -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);