I’m using a Map
to store the state of my component. Within this component, I have 3 groups, and in each group I have radio buttons. I have this array so that I can set values by default:
const defaultOptions = [
{ label: "Mark", value: "mark" },
{ label: "Steve", value: "steve" },
{ label: "Paul", value: "Paul" }
];
How can I set values by default using this array?
Here’s live DEMO
3
Answers
In your code there is no connection between the post (which has all the radio buttons) and the default ones. You can rely on luck and assume that first item of array is related to the Group A, and so on. But that is such an awful thing to do. I would not recommend doing any workaround to the current example. and think about another solution.
you must use the
checked
propYou can create the
Map
based on the array of defaults like so: