I have a react.js component that has a select with an onChange event handler. I'm reusing that component in a parent component that need to add a certain behaviour to the onChange, but only if certain conditions are met; if not, the behaviour of the child component should apply. The situation pseudocode would be like this:
var ParentComponent = React.createClass({ handleChange: function(event) { if (condition_on_event) { do_something_and_stop_the_handler(); } else { //execute_child_handler } }, render: function() { ... <ChildComponent /> } }); var ChildComponent = React.createClass({ handleChange: function(event) { //child handler code } }, render: function() { ... <select onChange={this.handleChange} /> } }); The idea is that the parent will execute something depending on the value of the select in the child. But only for one value, the rest of the values would execute the child handler normally.
In this situation, if I pass the parent handler as a prop, it would override the child handler, so I would need to duplicate code on the parent.
One solution that comes to mind is that I can pass the handler as a prop with a different name, to use it in the child handler, but it seems like a really dirty solution, as I'm adding an unnecessary prop to the child when is used in isolation.
Any tips?