UNPKG

refun

Version:

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

44 lines (37 loc) 1.24 kB
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray"; import { useState, useRef } from 'react'; import { isFunction, NOOP } from 'tsfn'; export var mapPressed = function mapPressed(props) { var origOnPressInRef = useRef(); var origOnPressOutRef = useRef(); var _useState = useState(false), _useState2 = _slicedToArray(_useState, 2), isPressed = _useState2[0], setIsPressed = _useState2[1]; var onPressInRef = useRef(NOOP); var onPressOutRef = useRef(NOOP); origOnPressInRef.current = props.onPressIn; origOnPressOutRef.current = props.onPressOut; if (onPressInRef.current === NOOP) { onPressInRef.current = function () { setIsPressed(true); if (isFunction(origOnPressInRef.current)) { origOnPressInRef.current(); } }; } if (onPressOutRef.current === NOOP) { onPressOutRef.current = function () { setIsPressed(false); if (isFunction(origOnPressOutRef.current)) { origOnPressOutRef.current(); } }; } return Object.assign({}, props, { isPressed: isPressed || Boolean(props.isPressed), onPressIn: onPressInRef.current, onPressOut: onPressOutRef.current }); }; //# sourceMappingURL=map-pressed.js.map