'React: get a list of a child's components

I can get a list of a component's children and the props on each child:

React.Children.map(children, child => {
    if (React.isValidElement(child)) {
        console.log(child.props);
    }
}

What if I wanted to grab the props off a component used within the child? So for example:

<Table>
  <CustomColumnA />
  <CustomColumnB />
</Table>

const CustomColumnA = () => {
  return (
      <Column
        prop1={true}
        prop2={"hello"} />
  );
}

From within Table, I want to grab prop1 and prop2. Is this possible? the Children.map code above will print empty objects, because CustomColumnA is being called with no props. But the component it wraps has props and I need access to that.

Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source