UNPKG

@nex-ui/utils

Version:

Utility functions for React components.

18 lines (16 loc) 425 B
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; } }); }; } export { mergeRefs };