Reactjs 使用“UseFormicContent()”时,如何防止出现“@typescript eslint/unbound method”错误?

Reactjs 使用“UseFormicContent()”时,如何防止出现“@typescript eslint/unbound method”错误?,reactjs,typescript,formik,Reactjs,Typescript,Formik,我刚刚将一些@typescript eslint模块更新为最新版本: "@typescript-eslint/eslint-plugin": "3.4.0", "@typescript-eslint/parser": "3.4.0", 我现在得到以下错误 22:9 error Avoid referencing unbound methods which may cause unintentional sc

我刚刚将一些
@typescript eslint
模块更新为最新版本:

"@typescript-eslint/eslint-plugin": "3.4.0",
"@typescript-eslint/parser": "3.4.0",
我现在得到以下错误

  22:9  error  Avoid referencing unbound methods which may cause unintentional scoping of `this`  @typescript-eslint/unbound-method
对于代码

const { setFieldTouched } = useFormikContext();
它的形式与


如何避免此错误?

实际上setFieldTouched不使用“this”引用,因此您可以禁用错误:

// eslint-disable-next-line @typescript-eslint/unbound-method
const { setFieldTouched } = useFormikContext();
第二个选项是调用setFieldTouched-like对象方法:

  const formikContext = useFormikContext();
  const setFieldTouched = (field: string, isTouched?: boolean, shouldValidate?: boolean) =>
formikContext.setFieldTouched(field, isTouched, shouldValidate);