Reactjs Formik onBlur触发所有选择组件错误
我为react-select组件创建了一个自定义组件,当我触发模糊事件时,每个react-select组件都会收到一条错误消息 这是组件代码:Reactjs Formik onBlur触发所有选择组件错误,reactjs,typescript,formik,react-select,Reactjs,Typescript,Formik,React Select,我为react-select组件创建了一个自定义组件,当我触发模糊事件时,每个react-select组件都会收到一条错误消息 这是组件代码: import { FieldProps, useField } from "formik"; import Select, { OptionsType } from "react-select"; interface Option { label: string; value: string; }
import { FieldProps, useField } from "formik";
import Select, { OptionsType } from "react-select";
interface Option
{
label: string;
value: string;
}
interface CustomSelectProps extends FieldProps
{
options: OptionsType<Option>;
}
export const MyMultiSelect = ( {
field,
form,
options,
}: CustomSelectProps ) =>
{
const fieldMeta = form.getFieldMeta( field.value );
return (
<>
<Select
name={ field.name }
value={ getValue() }
onChange={ onChange }
options={ options }
onBlur={ field.onBlur }
/>
<div className="field__validation">{ fieldMeta.touched && fieldMeta.error ? form.errors[ field.name ] : '' }</div>
</>
);
};
export default MyMultiSelect
从“formik”导入{FieldProps,useField};
从“反应选择”导入选择,{optionType};
接口选项
{
标签:字符串;
值:字符串;
}
界面CustomSelectProps扩展FieldProps
{
选项:选项类型;
}
导出常量MyMultiSelect=({
领域
形式,
选项,
}:CustomSelectProps)=>
{
const fieldMeta=form.getFieldMeta(field.value);
返回(
{fieldMeta.com&&fieldMeta.error?form.errors[field.name]:“”
);
};
导出默认MyMultiSelect
我试过使用handleBlur,但问题是相同的,我甚至尝试创建自定义模糊功能,但也没有帮助