我想在我的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”,
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
。