TypeError: _fieldRef$current.blur is not a function

TypeError: _fieldRef$current.blur is not a function

我将 useRefref 用于包含来自 Native Base 的 <Input> 的自定义 FieldInput 组件。

const fieldRef = useRef();
...
    const handleSubmitForm = (
    values: FormValues,
    helpers: FormikHelpers<FormValues>,
  ) => {
 ....
    fieldRef.current.blur();
    helpers.resetForm();
  };

但是,我在 fieldRef.current Object is possibly 'undefined'. 上遇到错误。所以,我这样改了:

const fieldRef = useRef<any>(null);
fieldRef.current?.blur();

这修复了内联错误,但在提交表单后,我仍然得到:

Warning: An unhandled error was caught from submitForm() TypeError: _fieldRef$current.blur is not a function

我该如何解决这个问题?任何解决方法都会有所帮助。我只想删除警告。

codesandbox: https://snack.expo.io/@nhammad/jealous-beef-jerky-fix

if 条件再添加一项检查。这应该会删除警告。

if (fieldRef && fieldRef.current && fieldRef.current.blur)