React selecting option with object as attribute value. You can make use of index of options:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | class Selector extends React.Component { contructor(props) { super(props); this.state = { obj: null } this.handleChange = this.handleChange.bind(this) } handleChange(e) { this.setState({obj: this.props.listOption[e.target.value].obj}) } render() { <select onChange={handleChange}> {this.props.listOption.map((option, index) => <option key={index} value={index}> {option.name} </option> )} </select> } } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.