尝试在 useEffect 挂钩内调用 redux 操作创建者,出现以下警告 -
React Hook useEffect has a missing dependency: 'getPlanQuotes'. Either include it or remove the dependency array react-hooks/exhaustive-deps
Run Code Online (Sandbox Code Playgroud)
这是 useEffect 钩子 -
const { getPlanQuotes } = props;
useEffect(() => {
getPlanQuotes();
}, []);
Run Code Online (Sandbox Code Playgroud)
所以我尝试使用禁用它// eslint-disable-next-line react-hooks/exhaustive-deps。像这样-
useEffect(() => {
getPlanQuotes();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
Run Code Online (Sandbox Code Playgroud)
但它仍然在控制台上抛出警告而没有react-hooks/exhaustive-deps指定
.eslintrc 配置-
{
"parser": "babel-eslint",
"extends": ["eslint:recommended", "plugin:react/recommended", "prettier"],
"env": {
"jest": true,
"browser": true,
"node": true,
"es6": true
},
"plugins": ["json", "prettier"], …Run Code Online (Sandbox Code Playgroud)