I am new to react, I want to select all radio buttons inside map loop.I am setting defaultChecked={index}, but it only selects the last radio button and the same is true for checked prop. Kindly help me.
availableCars.map((item, index) => (
<div className="item" key={index}>
<div className="carbox">
<div className="bluebg" />
<div className="choosedesc">
<h4>{item.vehicle_name}</h4>
</div>
<div>
<div className="selecttrip">
{!roundTrip || !oneWayTrip ? (
<React.Fragment>
{selectTripTypeError}
</React.Fragment>
) : null}
<label className="radiowrap">
Round Trip{' '}
<span className="blue">
{item.rt_price}
{item.currency == 'EUR'
? '€'
: 'GBP'
? '£'
: item.currency}
</span>
<input
type="radio"
value={item.rt_price}
defaultChecked={index}
onChange={e =>
onRoundTripChecked(
item.rt_price,
item.vehicle_id,
item.currency,
item.seconds_before_pick,
item.max_pax,
item.release_hours,
)
}
name="radio"
/>
<span className="checkmark" />
</label>
</div>
</div>
</div>
</div>
))