class FlavorForm extends React.Component {
constructor(props) {
super(props);
this.state = {value: 'b'};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(event) {
this.setState((state,props)=>{
value: event.target.value});
}
handleSubmit(event) {
alert('Your favorite flavor is: ' + this.state.value);
event.preventDefault();
}
render() {
return (
<form onSubmit={this.handleSubmit}>
<label>
Pick your favorite flavor:
<select multiple={true} value={['a', 'c']} onChange={this.handleChange}>
<option value="a">Grapefruit</option>
<option value="b">Lime</option>
<option value="c">Coconut</option>
<option value="d">Mango</option>
</select>
</label>
<input type="submit" value="Submit" />
</form>
);
}
}
ReactDOM.render(
<FlavorForm />,
document.getElementById('root')
);