The RadioGroup Component
Learn how to create a reusable RadioGroup component with React and Formik.
We'll cover the following...
What is a radio group?
A radio group is used when we want our users to select an option from a group of options (represented by radio buttons) in which only one button can be checked at a time.
Similar to the InputField
and Textarea
components, the RadioGroup
component needs a label
prop and a name
prop. In addition, it needs an options
prop. This is an array of the possible options a user can select. Each element in the array should be an object that gives the label of the option and the value of that option.
The label and value of an option should not be confused with the label and value of the component itself. Let’s use the image above to understand the difference.
The label of the radio group component is “Select an option.” In the component, there are three options. The label of each option is the text that is displayed to the user just beside the circle icon. The label for the first option is ...