UNPKG

refun

Version:

A collection of React Hook-enabled functions that compose harmoniously with each other. Similar to `recompose`, but:

43 lines (37 loc) 1.33 kB
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray"; import { useState, useRef } from 'react'; import { isFunction, NOOP } from 'tsfn'; export var mapHovered = function mapHovered(props) { var _useState = useState(false), _useState2 = _slicedToArray(_useState, 2), isHovered = _useState2[0], setIsHovered = _useState2[1]; var origOnPointerEnterRef = useRef(); var origOnPointerLeaveRef = useRef(); var onPointerEnterRef = useRef(NOOP); var onPointerLeaveRef = useRef(NOOP); origOnPointerEnterRef.current = props.onPointerEnter; origOnPointerLeaveRef.current = props.onPointerLeave; if (onPointerEnterRef.current === NOOP) { onPointerEnterRef.current = function () { setIsHovered(true); if (isFunction(origOnPointerEnterRef.current)) { origOnPointerEnterRef.current(); } }; } if (onPointerLeaveRef.current === NOOP) { onPointerLeaveRef.current = function () { setIsHovered(false); if (isFunction(origOnPointerLeaveRef.current)) { origOnPointerLeaveRef.current(); } }; } return Object.assign({}, props, { isHovered: isHovered || Boolean(props.isHovered), onPointerEnter: onPointerEnterRef.current, onPointerLeave: onPointerLeaveRef.current }); }; //# sourceMappingURL=map-hovered.js.map