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
|
Rev | Line | |
---|
[d565449] | 1 | import { useEffect, useState } from 'react';
|
---|
| 2 | import useMount from './useMount';
|
---|
| 3 | var 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 | };
|
---|
| 22 | export default useKeyboardJs;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.