I am writing an extended version of an input element. Here is a simplified version:
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 use it in context:
<MyInput placeholder="Test" value={this.state.myValue} onChange={function(event){ console.log('Trigger me second'); }} />
As you probably suspect, one onChange overrides the other depending on the order of the attributes.
Given this, do you think the cleanest way to implement support for multiple event handlers for the same event for the same element in such cases?
Edit
I managed to exchange
onChange and
{...this.props} for the component and use
changeHandler: function(event) { console.log('input_changeHandler change'); this.props.onChange(event); }
But I worry if it is safe.
javascript reactjs
Chavdar slavov
source share