source: imaps-frontend/node_modules/react-use/esm/useKeyboardJs.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 843 bytes
RevLine 
[d565449]1import { useEffect, useState } from 'react';
2import useMount from './useMount';
3var useKeyboardJs = function (combination) {
4 var _a = useState([false, null]), state = _a[0], set = _a[1];
5 var _b = useState(null), keyboardJs = _b[0], setKeyboardJs = _b[1];
6 useMount(function () {
7 import('keyboardjs').then(function (k) { return setKeyboardJs(k.default || k); });
8 });
9 useEffect(function () {
10 if (!keyboardJs) {
11 return;
12 }
13 var down = function (event) { return set([true, event]); };
14 var up = function (event) { return set([false, event]); };
15 keyboardJs.bind(combination, down, up, true);
16 return function () {
17 keyboardJs.unbind(combination, down, up);
18 };
19 }, [combination, keyboardJs]);
20 return state;
21};
22export default useKeyboardJs;
Note: See TracBrowser for help on using the repository browser.