小编ara*_*ind的帖子

在 useEffect 挂钩内使用 redux 操作创建者时,无法禁用 React-hooks/exhaustive-deps 警告

尝试在 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)

reactjs eslint react-redux react-hooks

1
推荐指数
1
解决办法
9794
查看次数

标签 统计

eslint ×1

react-hooks ×1

react-redux ×1

reactjs ×1