source: imaps-frontend/node_modules/react-use/esm/useHoverDirty.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: 1.2 KB
RevLine 
[d565449]1import { useEffect, useState } from 'react';
2import { off, on } from './misc/util';
3// kudos: https://usehooks.com/
4var useHoverDirty = function (ref, enabled) {
5 if (enabled === void 0) { enabled = true; }
6 if (process.env.NODE_ENV === 'development') {
7 if (typeof ref !== 'object' || typeof ref.current === 'undefined') {
8 console.error('useHoverDirty expects a single ref argument.');
9 }
10 }
11 var _a = useState(false), value = _a[0], setValue = _a[1];
12 useEffect(function () {
13 var onMouseOver = function () { return setValue(true); };
14 var onMouseOut = function () { return setValue(false); };
15 if (enabled && ref && ref.current) {
16 on(ref.current, 'mouseover', onMouseOver);
17 on(ref.current, 'mouseout', onMouseOut);
18 }
19 // fixes react-hooks/exhaustive-deps warning about stale ref elements
20 var current = ref.current;
21 return function () {
22 if (enabled && current) {
23 off(current, 'mouseover', onMouseOver);
24 off(current, 'mouseout', onMouseOut);
25 }
26 };
27 }, [enabled, ref]);
28 return value;
29};
30export default useHoverDirty;
Note: See TracBrowser for help on using the repository browser.