Detecting the type of Children components

suggest change

Sometimes 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.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents