Learning React and seeing the below code I read that React auto binds for you so the this
s in 1 and 2 work out well. I was wondering what would the this
in each one refer to if React didn't auto bind it for you? Wouldn't the 2 this
refer tot he input
element and thus not be able to get to the 1 this
?
var ContactForm = React.createClass({
propTypes: {
// ...
},
onNameInput: function(e) {
//1
this.props.onChange(Object.assign({}, this.props.value, {name: e.target.value}))
},
render: function() {
return React.createElement('form', {className: 'ContactForm'},
React.createElement('input', {
// ...
//2
onInput: this.onNameInput,
})
// ...
)
}
});