I'm writing an extended version of the input element. Here is a simplified version of it:
var MyInput = React.createClass({
render: function () {
return (
<div>
<input type="text" onChange={this.changeHandler} {...this.props} />
</div>
);
},
changeHandler: function(event){
console.log('Trigger me first');
}
});
I'm using it in a context like this:
<MyInput placeholder="Test" value={this.state.myValue} onChange={function(event){
console.log('Trigger me second');
}} />
As you are probably suspecting one onChange
overrides the other depending on the order of the attributes.
With that in mind, what do you think would be the cleanest way to implement support for multiple event handlers for the same event, for the same element in cases like this one?
Edit
I was able to swap
onChange
and {...this.props}
in the component and use
changeHandler: function(event)
{
console.log('input_changeHandler change');
this.props.onChange(event);
}
But I'm concerned if it's safe.