在react-hook-form中的“UseFormReturn”类型上不存在属性“errors”

bha*_*ATh 6 reactjs react-hook-form

当我使用react-hook-form时,我无法从react-hook-form解构错误对象。

 const { register, handleSubmit, reset, setValue, getValues, errors, formState } = useForm({
        resolver: yupResolver(validationSchema)
    });
Run Code Online (Sandbox Code Playgroud)

bha*_*ATh 15

我在官方文档中找到了答案。IE

 const { register, handleSubmit, reset, setValue, getValues, setError, formState: { errors }, formState } = useForm({
    resolver: yupResolver(validationSchema)
  });
Run Code Online (Sandbox Code Playgroud)