React.createClass({ ... })
render()
getInitialState()
this.state
this.props
var MyCounter = React.createClass({
render: function () {
return (
<button>I don't do anything... yet.</button>
);
}
});
var MyCounter = React.createClass({
getInitialState: function () {
return {
count: 0
};
},
onButtonClicked: function () {
this.setState({
count: this.state.count + 1
});
},
render: function () {
return (
<button onClick={this.onButtonClicked}>
Counter is {this.state.count}.
</button>
);
}
});
var MyCounter = React.createClass({
// ...
});
React.render(
<MyCounter />,
document.body
);
var Child = React.createClass({
onDeleteClick: function () {
this.props.onDelete();
},
render: function () {
return (
<button onClick={this.onDeleteClick}>
Delete
</button>
);
}
});
var Parent = React.createClass({
onChildDelete: function (childData) {
backend.delete(childData);
},
render: function () {
var childData = {};
return (
<Child onDelete={this.onChildDelete.bind(this, childData)} />
);
}
});