All files / src/_util get-props-from-children-by-type.ts

100% Statements 9/9
83.33% Branches 5/6
100% Functions 3/3
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 18 19 20 21 22 23 24 25 26              2x   2x 17x 33x 18x 15x       15x         2x 2x    
import React from "react";
import { isChildOfType } from "./is-child-of-type";
 
export function getPropsFromChildrenByType<P>(
  children: React.ReactNode,
  component: React.ComponentType<P>
) {
  const props = [] as P[];
 
  const dfs = (_children: React.ReactNode) => {
    React.Children.forEach(_children, child => {
      if (isChildOfType(child, component as any)) {
        props.push(child.props);
      } else Eif (
        React.isValidElement<{ children: any }>(child) &&
        child.props.children
      ) {
        dfs(child.props.children);
      }
    });
  };
 
  dfs(children);
  return props;
}