我刚刚将一些@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();它与Formik docs中的格式相同。
我如何避免这个错误?
发布于 2020-07-07 19:35:30
实际上setFieldTouched并不使用'this‘引用,所以你可以直接禁用error:
// eslint-disable-next-line @typescript-eslint/unbound-method
const { setFieldTouched } = useFormikContext();第二种选择是调用类似setFieldTouched的对象方法:
const formikContext = useFormikContext();
const setFieldTouched = (field: string, isTouched?: boolean, shouldValidate?: boolean) =>
formikContext.setFieldTouched(field, isTouched, shouldValidate);https://stackoverflow.com/questions/62640074
复制相似问题