首页 > 解决方案 > React JS - ESLint - 使用 UNSAFE_componentWillMount、UNSAFE_componentWillUpdate 和 UNSAFE_componentWillReceiveProps 忽略组件的规则

问题描述

目前,我收到这些 linting 错误:

ESLint: UNSAFE_componentWillUpdate should be placed after someFunction (react/sort-comp)

ESLint: Identifier 'UNSAFE_componentWillUpdate' is not in camel case. (camelcase)

目前,我无法找到正确的规则来添加以.eslintrc应用于前置UNSAFE_组件生命周期。我正在尝试使其同时适用于react/sort-comp规则camelcase,任何线索/帮助将不胜感激

标签: javascripthtmlreactjsfrontendeslint

解决方案


您可以将其添加到您的 eslint

"camelcase": [
  "error", {
    "ignoreDestructuring": true,
    "allow": [ "^UNSAFE_" ]
  }
],

这基本上只允许所有重命名的UNSAFE_生命周期方法。


推荐阅读