UNPKG

@etsoo/react

Version:

TypeScript ReactJs UI Independent Framework

27 lines (26 loc) 626 B
/** * Combined refs * @param refs Refs * @returns Callback */ export function useCombinedRefs(...refs) { return (target) => { // Ignore null reference if (target == null) return; // Update all refs refs.forEach((ref) => { // Null ref if (!ref) return; // Callback function if (typeof ref === "function") { ref(target); } else { // as any to update readonly property Reflect.set(ref, "current", target); } }); }; }