UNPKG

refun

Version:

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

46 lines (37 loc) 1.29 kB
Object.defineProperty(exports, "__esModule", { value: true }); exports.mapHovered = void 0; var _react = require("react"); var _tsfn = require("tsfn"); const mapHovered = props => { const [isHovered, setIsHovered] = (0, _react.useState)(false); const origOnPointerEnterRef = (0, _react.useRef)(); const origOnPointerLeaveRef = (0, _react.useRef)(); const onPointerEnterRef = (0, _react.useRef)(_tsfn.NOOP); const onPointerLeaveRef = (0, _react.useRef)(_tsfn.NOOP); origOnPointerEnterRef.current = props.onPointerEnter; origOnPointerLeaveRef.current = props.onPointerLeave; if (onPointerEnterRef.current === _tsfn.NOOP) { onPointerEnterRef.current = () => { setIsHovered(true); if ((0, _tsfn.isFunction)(origOnPointerEnterRef.current)) { origOnPointerEnterRef.current(); } }; } if (onPointerLeaveRef.current === _tsfn.NOOP) { onPointerLeaveRef.current = () => { setIsHovered(false); if ((0, _tsfn.isFunction)(origOnPointerLeaveRef.current)) { origOnPointerLeaveRef.current(); } }; } return { ...props, isHovered: isHovered || Boolean(props.isHovered), onPointerEnter: onPointerEnterRef.current, onPointerLeave: onPointerLeaveRef.current }; }; exports.mapHovered = mapHovered;