let ProductCategoryRow = React.createClass({ render: function () { return ({this.props.category}); } }); let ProductRow = React.createClass({ render: function () { let name = this.props.product.stocked ? this.props.product.name : {this.props.product.name}; return ( {name} {this.props.product.price} ); } }); let ProductTable = React.createClass({ render: function () { let rows = []; let lastCategory = null; this.props.products.forEach(function (product) { // Apply name and stock filters. if (product.name.indexOf(this.props.filterText) === -1 || (!product.stocked && this.props.inStockOnly)) { return; } if (product.category !== lastCategory) { rows.push(); } rows.push(); lastCategory = product.category; }.bind(this)); return ( {rows}
Name Price
); } }); let SearchBar = React.createClass({ handleChange: function () { this.props.onUserInput( this.refs.filterTextInput.value, this.refs.inStockOnlyInput.checked ); }, render: function () { return (

{" "} Only show products in stock

); } }); let FilterableProductTable = React.createClass({ getInitialState: function () { let state = { filterText: "", inStockOnly: false }; return state; }, handleUserInput: function (filterText, inStockOnly) { this.setState({ filterText: filterText, inStockOnly: inStockOnly }); }, render: function () { return (
); } }); let PRODUCTS = [ { category: "Sporting Goods", price: "$49.99", stocked: true, name: "Football" }, { category: "Sporting Goods", price: "$9.99", stocked: true, name: "Baseball" }, { category: "Sporting Goods", price: "$29.99", stocked: false, name: "Basketball" }, { category: "Electronics", price: "$99.99", stocked: true, name: "iPod Touch" }, { category: "Electronics", price: "$399.99", stocked: false, name: "iPhone 5" }, { category: "Electronics", price: "$199.99", stocked: true, name: "Nexus 7" } ]; ReactDOM.render( , document.getElementById("content") );