zatziky zatziky - 3 months ago 34
React JSX Question

React-bootstrap: onChange invoked only once for "select"

Here is a fiddle with the example demonstrating this code:

render: function() {
return (
<FormControl componentClass="select" onChange={console.log("changed")}>
<option value="1">A</option>
<option value="2">B</option>
</FormControl>
);
}


onChange()
is invoked only when my component gets rendered.

I want to react on a different option. So if I change 'A' to 'B' I want the component to fire
onChange()
event. What am I missing?

Answer

Write a method named handleSelectChange

handleSelectChange: function(event) {
    //Do sth
}

and call it like onChange={this.handleSelectChange}