L
L
lucky42020-08-31 21:52:11
React
lucky4, 2020-08-31 21:52:11

How to create a radio-button group in Formik?

I do user registration using Formik.
I googled how to make the button radio shape, but there is a problem.

export default function RadioButton({ options }) {
    return (
        <Field component="div">
            {
                options.map((option, index) => {
                    return (
                        <div className="radio" key={ index }>
                            <input
                                type="radio"
                                id={ option.id }
                                value={ option.value }
                            />
                            <label htmlFor={option.id}>{option.key}</label>
                        </div>
                    )
                })
            }
        </Field>
    )
}


Firstly, I have all radio buttons selected as checkboxes)
The second thing that worries me is handleChange and handleBlur, how can I add them to the component too?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel, 2020-09-01
@Asokr

First, you need to add a name for the radio inputs....
The main page has everything you need

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question