@nex-ui/utils
Version:
Utility functions for React components.
20 lines (17 loc) • 449 B
JavaScript
function mergeRefs(...refs) {
const list = refs.filter((ref)=>ref);
if (list.length === 1) {
return list[0];
}
return (node)=>{
list.forEach((ref)=>{
if (typeof ref === 'function') {
ref(node);
} else if (ref && typeof ref === 'object' && 'current' in ref) {
ref.current = node;
}
});
};
}
exports.mergeRefs = mergeRefs;
;