Detecting the type of Children components
suggest changeSometimes it’s useful to know the type of a child component when iterating through them. To iterate the children, use the React.Children.map utility:
React.Children.map(this.props.children, (child) => {
if (child.type === MyComponentType) {
...
}
});
The child object exposes the type property which you can compare to a specific component.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents