Composing components

We've talked a lot about composability in the way of creating components by composing React's default components. However, we haven't showed how to compose custom components into bigger components.

As you might have guessed, this should be a pretty simple exercise, and to demonstrate how this works, we are going to implement a component to list investments, as follows:

var InvestmentList = React.createClass({
  render: function () {
    var onClickDelete = this.props.onClickDelete;

    var listItems = this.props.investments.map(function (investment) {
      return <InvestmentListItem investment={investment}
                  onClickDelete={onClickDelete.bind(null, investment)}/>;
    });

    return <ul className="investment-list">{listItems}</ul>;
  }
});

It is as simple ...

Get Jasmine JavaScript Testing - Second Edition 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.