I have a selectInput component made with React select which I have inside a Formik Form. I am trying to get my Formik values to update with the values coming back from React Select. What is the best way to get this done?
Inside my Formik Form:
const initialValues = {
firstName: '',
lastName: '',
jobPosition: '',
email: '',
phoneNumber: '',
languages: [],
files: []
};
<SelectInput
name='languages'
options={languages}
isMulti={true}
onChange={handleChange}
type='select'
/>
my SelectInput component:
import React from 'react'
import Select from "react-select";
import { inputStyles } from './styles';
import PropTypes from 'prop-types';
import { useField } from 'formik';
const SelectInput = ({ options, placeholder, isMulti, ...props }) => {
const [field] = useField(props)
return (
<div style={{ marginTop: '1.5rem' }}>
<Select
{...field}
styles={inputStyles}
className="basic-single"
classNamePrefix="select"
isClearable={true}
isSearchable={true}
placeholder={placeholder}
options={options}
isMulti={isMulti}
/>
</div>
)
}
In its current state when selecting an option I receive a type Error:
Formik.tsx:600 Uncaught TypeError: Cannot read properties of undefined (reading 'type')