You can use a managed input or an unmanaged input. Below is an example for each of the solutions.
Before posting this, let me add some useful tips and links for you:
refs . , . , refs; .
key , . . ,
. , .
value .
, , . - :
constructor() {
super();
this.state = {checkedRadio: null};
}
changeRadio(e) {
this.setState(checkedRadio: e.target.value);
}
var options = [{id:1,nm:"Appointment fixed"},{id:2,nm:"Call later"},{id:3,nm:"Wrong number"},{id:4,nm:"Don't call again"},{id:5,nm:"Call later"}];
{options.map((item,i) => {
return (
<div key={item.id} onChange={(i)=>this.callOptions(i)}>
<label className="radio-inline"><input type="radio" checked={this.state.checkedRadio == i} ref={(el) => this["myRadioRef" + i] = el} value={item.id} onChange={this.changeRadio} />{item.nm}</label>
</div>
);
})}
- . , , - name . :
var options = [{id:1,nm:"Appointment fixed"},{id:2,nm:"Call later"},{id:3,nm:"Wrong number"},{id:4,nm:"Don't call again"},{id:5,nm:"Call later"}];
{options.map((item,i) => {
return (
<div key={item.id} onChange={(i)=>this.callOptions(i)}>
<label className="radio-inline"><input type="radio" name="myRadio" ref={(el) => this["myRadioRef" + i] = el} value={item.id} onChange={this.changeRadio} />{item.nm}</label>
</div>
);
})}