react-tesna-utils
Version:
A versatile utility library featuring optimized functions for data manipulation, clipboard handling, text truncation, comparison, validation, and more. Designed for modern JavaScript and TypeScript projects with efficient and reusable solutions.
27 lines (26 loc) • 653 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.composeRef = void 0;
const fillRef = (ref, node) => {
if (typeof ref === 'function') {
ref(node);
}
else if (typeof ref === 'object' && ref && 'current' in ref) {
ref.current = node;
}
};
/**
* Merge refs into one ref function to support ref passing.
*/
const composeRef = (...refs) => {
const refList = refs.filter(Boolean);
if (refList.length <= 1) {
return refList[0];
}
return (node) => {
refs.forEach(ref => {
fillRef(ref, node);
});
};
};
exports.composeRef = composeRef;