Updating state when using multiple Radio Groups #6126
Unanswered
deltasierra96
asked this question in
Q&A
Replies: 1 comment 1 reply
-
First, I think it's a bit confusing to call both entities "variants", so for the purpose of this, I'll call them feature (i.e. Color) and variant (i.e. Gloss Black). There are a lot of ways to do this, but I think a good option is to store selected state in the key-value format For your selection handler, you'll need to pass in the feature id and the newly selected variant id for that feature. Ex: let handleOnChange = (featureId, newSelectedVariantId) => {
setSelected((prevSelected) => new Map([...prevSelected, [featureId, newSelectedVariantId]]))
} Then, to get the output array you want, you can use Object.values() if you're using an object, or Map.prototype.values() if using a Map. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to create a variant selector that currently looks like the following.
This is the data I am working with.
How would one go about creating/updating state that contains the ID's of the selected Radio Group option for each Radio Group?
Ultimately I would end up with an array of unique selected variation id's and when selecting a new radio option, it would replace/update the necessary id, for example:
Beta Was this translation helpful? Give feedback.
All reactions