MBehtemam MBehtemam - 1 year ago 62
React JSX Question

Getting text of Radio in Ant.desing and React.js

I'm using Ant Desing Radio with react js for creating a radio button. and i create a Radio button like this with map function :

<RadioGroup onChange={this.setActivityType} defaultValue={this.props.activityTypes[0].value} size="large">

{this.props.activityTypes.map((type,i)=>(
<RadioButton key={i} value={type.value} >{type.name}</RadioButton>
))}
</RadioGroup>


also in
onChange={this.setActivityType}
function i can see
e.target.value
that is passed as
value={type.value}
i also need name of between tag of
<RadioButton>
, the
{type.name}
but i can't see any properties in developer tools or antd docs ? dose anyone know how to access this property and save it to state with onChange?

Answer Source

To access the name of each RadioButton define a name property with each RadioButton like this:

<RadioButton key={i} value={type.value} name={type.name}>{type.name}</RadioButton>

Now inside onChange method access that name by e.target.name.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download