eact.Children code example
Example 1: React.createElement
const e = React.createElement;
ReactDOM.render(
e('div', null, 'Hello World'),
document.getElementById('root')
);
Example 2: React Children map example
export default class MovieBrowser extends React.Component {
render() {
const currentPlayingTitle = 'Mad Max: Fury Road';
const childrenWithExtraProp = React.Children.map(this.props.children, child => {
return React.cloneElement(child, {
isPlaying: child.props.title === currentPlayingTitle
});
});
return (
<div className="movie-browser">
{childrenWithExtraProp}
</div>
);
}
}