I was reading documentation on \"onChange\" and I am curious as to what I would do if my forum has multiple fields like select boxes, checkboxes, text areas and inputs? Do I
@FakeRainBrigand 's answer is pretty cool.
I want to share one in JavaScript style (use high-order function), much shorter:
/** @jsx React.DOM */
var App = React.createClass({
getInitialState: function () {
return {
username: '',
password: ''
}
},
handleChange: function (key) {
return function (e) {
var state = {};
state[key] = e.target.value;
this.setState(state);
}.bind(this);
},
render: function(){
console.log(JSON.stringify(this.getFormData(), null, 4));
return (
{JSON.stringify(this.getFormData(), null, 4)}
);
}
});
React.renderComponent( , document.body);