1export default class SomeComponent extends React.Component {
2 render() {
3 const childrenWithWrapperDiv = React.Children.map(this.props.children, child => {
4 return (
5 <div className="some-component-special-class">{child}</div>
6 );
7 });
8
9 return (
10 <div className="some-component">
11 <p>This component has {React.Children.count(this.props.children)} children.</p>
12 {childrenWithWrapperDiv}
13 </div>
14 );
15 }
16}
17
1export default class MovieBrowser extends React.Component {
2 render() {
3 const currentPlayingTitle = 'Mad Max: Fury Road';
4 const childrenWithExtraProp = React.Children.map(this.props.children, child => {
5 return React.cloneElement(child, {
6 isPlaying: child.props.title === currentPlayingTitle
7 });
8 });
9
10 return (
11 <div className="movie-browser">
12 {childrenWithExtraProp}
13 </div>
14 );
15 }
16}
17