I have a bit of code that looks like this:
const companies = [
{
id: 1,
name: "Acme"
},
{
id: 2,
name: "Beta"
}
];
....
<RadioGroup
aria-label={title}
name={title}
value={this.state.value}
onChange={this.handleChange}
>
{companies.map(v => (
<FormControlLabel
value={v.name}
control={<Radio />}
label={v.name}
key={v.name}
/>
))}
/>
</RadioGroup>
The tricky bit is that I have to bind a string type to radio button, for all intents and purposes the company name works.
However, later when I submit the form, I need the whole companies object.
I could do something like:
company = companies.filter(v => v.name === this.state.value);
but it's a little messy.
Is there a simpler way to do this, that I'm missing?