我如何传递道具来回应处理程序组件?
我的代码如下:
var Dashboard = require('./Dashboard');
var Comments = require('./Comments');
var Index = React.createClass({
答案 0 :(得分:0)
var Index = React.createClass({
getInitialState: function () {
return { input1: '', input2: '' };
},
handleinput1Change: function (e) {
this.setState({ input1: e.target.value });
},
handleinput2Change : function (e) {
this.setState({ input2: e.target.value });
},
handleSubmit: function (e) {
e.preventDefault();
var text1 = this.state.input1.trim();
var text2 = this.state.input2.trim();
if (!text1 || !text2) {
return;
}
this.props.onCommentSubmit({ input1: text1, input2: text2 });
this.setState({ input1: '', input2: '' });
},
render: function () {
return (
<form className="commentForm" onSubmit={this.handleSubmit}>
<input
type="text"
placeholder="Enter something"
value={this.state.input1}
onChange={this.handleinput1Change}
/>
<input
type="text"
placeholder="Enter something"
value={this.state.input2}
onChange={this.handleinput2Change} />
<input type="submit" value="Post" />
</form>
);
}
});