All files / src/utils mergeRefs.ts

81.82% Statements 9/11
62.5% Branches 5/8
100% Functions 2/2
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17      204x 204x 204x 204x 408x 590x 576x 14x 14x          
import * as React from 'react';
 
export function mergeRefs(...refs: Array<React.Ref<any> | undefined>) {
  const filteredRefs = refs.filter(Boolean);
  Iif (!filteredRefs.length) return null;
  Iif (filteredRefs.length === 0) return filteredRefs[0];
  return (instance: any) => {
    for (const ref of filteredRefs) {
      if (typeof ref === 'function') {
        ref(instance);
      } else Eif (ref) {
        (ref as React.MutableRefObject<any>).current = instance;
      }
    }
  };
}