react-responsive-select icon indicating copy to clipboard operation
react-responsive-select copied to clipboard

using react-responsive-select with formik+typescript

Open repka3 opened this issue 4 years ago • 2 comments

I'm currently facing an issue trying to use react-responsive-select with formik and typescript.

This is how i'm using it:

`

                     <Select
                    name="tipo"
                    modalCloseButton={<ModalCloseButton />}
                    options={[
                        { value: 'C', text: 'Clienti' },
                        { value: 'F', text: 'Fornitori' },
                        { value: 'V', text: 'Vettori' },
                        { value: 'R', text: 'Referenti' },
                        { value: 'A', text: 'Agenti' },
                        { value: 'O', text: 'Collaboratori' },
                        { value: 'L', text: 'Altro' },
                    ]}

                    caretIcon={<CaretIcon />}

                    prefix="       "

                    selectedValue={formik.values.tipoEntry}

                    onChange={newValue => {
                        console.log("onChange", newValue);
                        console.log(formik.values.tipoEntry);
                        formik.handleChange({
                            target: {
                                value: newValue.value,
                                name: newValue.name
                            }
                        });
                    }}

                />

`

Typescript complains about newValue.value and newValue.name: Property 'value' does not exist on type '{ altered?: boolean | undefined; text?: string | undefined; name?: string | undefined; value?: string | undefined; } | { altered?: boolean | undefined; options: { text?: string | undefined; name?: string | undefined; value?: string | undefined; }[]; }'. Property 'value' does not exist on type '{ altered?: boolean | undefined; options: { text?: string | undefined; name?: string | undefined; value?: string | undefined; }[]; }'. TS2339

It seems to me something wrong with the type of newValue. Any suggestion?

repka3 avatar May 11 '21 07:05 repka3

Thanks for the example. Let me have a look

benbowes avatar May 13 '21 06:05 benbowes

Hi @repka3 .

Did you try the Formik example on the demo site?

benbowes avatar May 13 '21 06:05 benbowes