chenglou / react-radio-group

Better radio buttons.
MIT License
445 stars 75 forks source link

Iterate through array to get radio values #30

Closed stephmilovic closed 8 years ago

stephmilovic commented 8 years ago

Hello. I am trying to iterate through an array to get the values for the Radio components. However, I'm having issues:

renderRadios(options){
    let radioItems = [];
    for (let i = 0; i < options.length; i++) {
      const option = options[i];
      radioItems.push( <Radio value={option.value} label={option.label} /> )
    }
    return radioItems;
}
render() {
  return (
    <div>
      <h1>&x-{this.props.parameterData.param}={this.props.parameterData.default}</h1>
      <RadioGroup
        name={this.props.parameterData.param}
        selectedValue={this.state.selectedValue}
        onChange={this.handleChange}>
        {Radio => (
          <div>
            {Object.keys(this.props.options).map(this.renderRadios)}
          </div>
        )}
     </RadioGroup>
   </div>
  );
}

Since Radio is not defined, I am getting an error. If I put the loop right in the Radio => function, I get syntax errors. How can I accomplish this?

I've made a JSFiddle here.

kailshar commented 8 years ago

What is the solution here ?