Accessing a component's children

In React when we want to access the inner HTML of a component or a component that's been embedded inside of a component we can use this.props.children. This feature is very similar to Angular's Transclusion, WebComponent's Contents or Ember's Yield. To demonstrate this we are going to update the button from our previous example to be the Button component shown in the following code:

var Button = React.createClass({
   render: function() {
       return (
<button onClick={this.props.onClick}>

What we have created here is Button component that can have its opening and closing tags wrapped around the HTML elements and React components that it wants to display within the button that it ...

Get Mastering React now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.