Skip to content

Instantly share code, notes, and snippets.

@Rosaniline
Last active August 25, 2016 09:26
Show Gist options
  • Save Rosaniline/fdd8dfdd259c512551beb745e6d3b61c to your computer and use it in GitHub Desktop.
Save Rosaniline/fdd8dfdd259c512551beb745e6d3b61c to your computer and use it in GitHub Desktop.
MichaelGodHelpPlease
Child Component
onChangeHandler (val) {
// Is there anyway that I can share the handler among different Select while keeping in mind that which Select(corresponding to entry) is called ?
this.props.onChange(entry, val)
}
render () {
<Select name="select1" value={this.props.data["select1"]} options=this.props.options onChange={this.onChangeHandler} />
<Select name="select2" value={this.props.data["select2"]} options=this.props.options onChange={this.onChangeHandler} />
<Select name="select3" value={this.props.data["select3"]} options=this.props.options onChange={this.onChangeHandler} />
<Select name="select4" value={this.props.data["select4"]} options=this.props.options onChange={this.onChangeHandler} />
}
Parent Component
this.props.data = [{select1: 123, select2: 123 ...}, {}, {}]
this.props.selected_row = 1
onChangeHandler (entry, val) {
//
}
render () {
<Child data={this.state.data[this.props.selected_row] onChange={this.onChangeHandler.bind(this)} />
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment