UNPKG

reshow-build

Version:
37 lines (32 loc) 757 B
//@ts-check import * as React from "react"; import { HAS, FUNCTION } from "reshow-constant"; /** * @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 (HAS(refCb, "current")) { /** @type {React.RefObject} */refCb.current = el; } else if (FUNCTION === typeof refCb) { /** @type {Function} */refCb(el); } }; /** * @param {Element|null} el * @param {RefType[]} refArr */ export var mergeRef = function mergeRef(el, refArr) { if (refArr === void 0) { refArr = []; } return refArr.forEach(function (ref) { return ref && assignEl(el, ref); }); };