我正在尝试使用 yup 概念实现对反应选择(单选)的验证。但我收到此错误:
对象作为 React 子对象无效(找到:带有键 {label, value} 的对象)。如果您打算渲染一组子项,请改用数组。
我想知道如何在验证模式中为 yup 概念分配对象
<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> ); }}