Digging into components

Let's dig further into components and master them. We'll look at component composition and ownership. Learning this will help us build complex reactive UIs that are easier to manage.

Component composition

Composability is a feature that lets you use a component inside another component's render method.

Let's look at a basic example of component composition. First, create a new container element. To do so, place the following code in the body tag:

<div id="container5"></div>

Here is the component composition example code. Place this code in the script tag that's compiled by Babel:

var ResponsiveImage = React.createClass({ render: function(){ var imgWidth = { width: "100%" } return ( <img src={this.props.src} style={imgWidth} ...

Get JavaScript: Moving to ES2015 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.