I want to create a Dynamic Radio button based on API response and store the value clicked in the state.
Here is the code for radio button:
<section className='radio-content-brand'>
<span className='company-type-brand'>Campaign Type</span>
{campaign_type.map(type => (
<div className='div-brand'>
<div className="size-box-brand">
<input
type="radio"
value={this.state.campaign}
checked={this.state.campaign === type.campaign_type}
onChange={this.handleChangeCompanyType}
/>
<label className='label-brand'>
<span style={{ color: "#606060", fontSize: 25 }}>{type.campaign_type}</span>
</label>
</div>
</div>
))}
</section>
onChange function is here:
handleChangeCompanyType(event) {
console.log(event.target.value);
this.setState({ campaign: event.target.value })
}
Here are 2 states campaign where I want the clicked radio button value to be stored and campaign_type where the list of responses is stored.
The issue is when clicked on the radio button there is no response i.e event.target.value is empty.
this.state.campaign?event.target.valuereturns an empty string.