I am trying to implement validation for react-select (single-select) using yup concept. But i am getting this error:
Objects are not valid as a React child (found: object with keys {label, value}). If you meant to render a collection of children, use an array instead.
I want to know how to assign objects in validation schema for yup concept
<Formik
initialValues={{
department:"",
}}
onSubmit={this.submitForm}
validationSchema={Yup.object().shape({
department: Yup.object().shape({
label: Yup.string().required(),
value: Yup.string().required(),
}),
})}>
{ props => {
const {
values,
touched,
errors,
isSubmitting,
handleChange,
handleBlur,
handleSubmit,
selectedOption
} = props;
return (
<React.Fragment>
<InputLabel shrink htmlFor={'department'}>
Department</InputLabel>
<Select
inputId="department"
options={options}
value={values.department}
onChange={this.onChangeOption}
onBlur={handleBlur}
/>
{errors.department && touched.department && ( {errors.department} )}
Submit </div> </React.Fragment> ); }}