Im making a react component that creates multiple buttons but I dont know how to handle the action depending on which button is pressed, this is the component:
var SingleChoiceGroup = React.createClass({
render(){
var numberOfButtons = this.props.numberOfButtons;
var prefix = this.props.prefix;
var buttons = [];
for(var i = 0;i<numberOfButtons;i++){
buttons.push(
<Button value={i} onClick={() => this.props.selectedItem(i)}>{prefix + " " + (i+1)}</Button>
);
}
return(
<div>
{buttons}
</div>
)
}
});
And this is the method were I want to get the parameter:
var AnotherComponent = React.createClass({
selectedDay(i){
// Here I want to read the index parameter from the other component.
},
render(){
<SingleChoiceGroup selectedItem={() => this.selectedDay()} numberOfButtons={7} prefix={"Text"}/>
}
});