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
1//Below I use the React.createElement() function to create a virtual DOM
2//representation of a <li> element node containing a text node of one (a.k.a.,
3//React text) and an id of li1.
4
5var reactNodeLi = React.createElement('li', {id:'li1'}, 'one');
6
7
1class Hello extends React.Component {
2 render() {
3 return React.createElement('div', null, `Hello ${this.props.toWhat}`);
4 }
5}
6
7ReactDOM.render(
8 React.createElement(Hello, {toWhat: 'World'}, null),
9 document.getElementById('root')
10);
1const element = React.createElement(
2 'h1',
3 {className: 'greeting'},
4 'Hello, world!'
5);