如何启用详尽穷举棉绒规则?

问题描述 投票:2回答:1

我想在我的create-react-app中启用exhaustive-deps棉绒规则。它是否默认随附?似乎并非如此,因为我对此代码没有任何抱怨:

const [error, setError] = useState(false);
useEffect(() => {
        console.log(error)
        fetchPersonAndSuggestions();
}, []);

我尝试做

npm install eslint-plugin-react-hooks@next

但仍然没有成功。

CRA版本:“反应脚本”:“ 3.0.1”,

reactjs react-hooks create-react-app eslint lint
1个回答
1
投票

https://reactjs.org/docs/hooks-rules.html#eslint-plugin

将以下插件和规则添加到您的lint配置中:

{
  "plugins": [
    // ...
    "react-hooks"
  ],
  "rules": {
    // ...
    "react-hooks/rules-of-hooks": "error", // Checks rules of Hooks
    "react-hooks/exhaustive-deps": "warn" // Checks effect dependencies
  }
}

您可以(可能)在项目的根目录中找到您的eslint配置文件。常用名称是.eslintrc.eslintrc.json.eslintrc.config

© www.soinside.com 2019 - 2024. All rights reserved.