Skip to content

Instantly share code, notes, and snippets.

@chiedo
Last active October 22, 2015 12:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chiedo/bfdbfa9ea55730706da5 to your computer and use it in GitHub Desktop.
Save chiedo/bfdbfa9ea55730706da5 to your computer and use it in GitHub Desktop.
let React = require('react');
class ClothingSizePicker extends React.Component {
constructor() {
super();
this.state = {size: 'S'};
this._handleChange = this._handleChange.bind(this);
}
_handleChange(e) {
e.preventDefault();
this.setState({size: e.target.value});
}
render(){
let select;
let options;
let sizes = ['S', 'M', 'L', 'XL'];
let state = this.state;
options = sizes.map(function(size){
return (
<option key={sizes.indexOf(size)} value={size}>{size}</option>
);
});
return (
<select defaultValue={state.size} onChange={this._handleChange}>
{options}
</select>
);
};
};
module.exports = ClothingSizePicker;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment