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;
}
|