source: imaps-frontend/node_modules/react-use/lib/useHoverDirty.js

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

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.3 KB
RevLine 
[d565449]1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var react_1 = require("react");
4var util_1 = require("./misc/util");
5// kudos: https://usehooks.com/
6var useHoverDirty = function (ref, enabled) {
7 if (enabled === void 0) { enabled = true; }
8 if (process.env.NODE_ENV === 'development') {
9 if (typeof ref !== 'object' || typeof ref.current === 'undefined') {
10 console.error('useHoverDirty expects a single ref argument.');
11 }
12 }
13 var _a = react_1.useState(false), value = _a[0], setValue = _a[1];
14 react_1.useEffect(function () {
15 var onMouseOver = function () { return setValue(true); };
16 var onMouseOut = function () { return setValue(false); };
17 if (enabled && ref && ref.current) {
18 util_1.on(ref.current, 'mouseover', onMouseOver);
19 util_1.on(ref.current, 'mouseout', onMouseOut);
20 }
21 // fixes react-hooks/exhaustive-deps warning about stale ref elements
22 var current = ref.current;
23 return function () {
24 if (enabled && current) {
25 util_1.off(current, 'mouseover', onMouseOver);
26 util_1.off(current, 'mouseout', onMouseOut);
27 }
28 };
29 }, [enabled, ref]);
30 return value;
31};
32exports.default = useHoverDirty;
Note: See TracBrowser for help on using the repository browser.