reshow-build
Version:
React super cloneElement and createElement
41 lines (36 loc) • 986 B
JavaScript
;
var _interopRequireWildcard = require("reshow-runtime/helpers/interopRequireWildcard");
exports.__esModule = true;
exports.mergeRef = void 0;
var React = _interopRequireWildcard(require("react"));
var _reshowConstant = require("reshow-constant");
//@ts-check
/**
* @typedef {React.RefObject|Function|undefined} RefType
*/
/**
* @typedef {React.ReactElement|HTMLElement} Element
*/
/**
* @param {Element|null} el
* @param {RefType} refCb
*/
var assignEl = function assignEl(el, refCb) {
if ((0, _reshowConstant.HAS)(refCb, "current")) {
/** @type {React.RefObject} */refCb.current = el;
} else if (_reshowConstant.FUNCTION === typeof refCb) {
/** @type {Function} */refCb(el);
}
};
/**
* @param {Element|null} el
* @param {RefType[]} refArr
*/
var mergeRef = exports.mergeRef = function mergeRef(el, refArr) {
if (refArr === void 0) {
refArr = [];
}
return refArr.forEach(function (ref) {
return ref && assignEl(el, ref);
});
};