let ProductCategoryRow = React.createClass({
name: "ProductCategoryRow",
componentDidMount: function () {
console.log("Component did mountDM", this.name, "State", this.state, "Props", this.props);
},
getInitialState: function () {
console.log("Get Initial State", this.name);
return null;
},
render: function () {
return (
{this.props.category} |
);
}
});
let ProductRow = React.createClass({
name: "ProductRow",
componentDidMount: function () {
console.log("Component did mountDM", this.name, "State", this.state, "Props", this.props);
},
getInitialState: function () {
console.log("Get Initial State", this.name);
return null;
},
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({
name: "ProductTable",
componentDidMount: function () {
console.log("Component did mountDM", this.name, "State", this.state, "Props", this.props);
},
getInitialState: function () {
console.log("Get Initial State", this.name);
return null;
},
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 (
);
}
});
let SearchBar = React.createClass({
name: "SearchBar",
componentDidMount: function () {
console.log("Component did mountDM", this.name, "State", this.state, "Props", this.props);
},
getInitialState: function () {
console.log("Get Initial State", this.name, "Props", this.props);
return null;
},
render: function () {
return (
);
}
});
let FilterableProductTable = React.createClass({
name: "FilterableProductTable",
componentDidMount: function () {
console.log("Component did mountDM", this.name, this.name, "State", this.state, "Props", this.props);
},
getInitialState: function () {
let state = {
filterText: "ball",
inStockOnly: true
};
console.log("Get Initial State", this.name, state, "Props", this.props);
return state;
},
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")
);