[d565449] | 1 | "use strict";
|
---|
| 2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
| 3 | var react_1 = require("react");
|
---|
| 4 | var util_1 = require("./misc/util");
|
---|
| 5 | // kudos: https://usehooks.com/
|
---|
| 6 | var 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 | };
|
---|
| 32 | exports.default = useHoverDirty;
|
---|