简体   繁体   English

如何正确修复 React Hook useCallback 缺少依赖项

[英]How to properly fix React Hook useCallback has a missing dependency

I updated my Eslint rules using airbnb in my React typescript project.我在我的 React typescript 项目中使用airbnb更新了我的 Eslint 规则。

I get those errors now:我现在收到这些错误:

React Hook useCallback has a missing dependency: 'setCookie'. React Hook useCallback 缺少依赖项:'setCookie'。 Either include it or remove the dependency array.eslintreact-hooks/exhaustive-deps包含它或删除依赖项 array.eslintreact-hooks/exhaustive-deps

I have this in the extend property inside eslintrc.js:我在 eslintrc.js 的扩展属性中有这个:

extends: [
    'airbnb',
    'airbnb-typescript',
    'airbnb/hooks',
    'plugin:react/recommended',
    'plugin:jest/recommended',
    'plugin:prettier/recommended',
],

How to properly fix those errors?如何正确修复这些错误? When is it a good practice to add or not to add the dependencie prop(s)?什么时候添加或不添加依赖道具是一个好习惯?

如果您完全删除它,而不是抛出错误,这是非常糟糕的体验,我想通过将其添加到您的 eslintrc 规则中来发出警告:

"react-hooks/exhaustive-deps": "warn"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React Hook useCallback 缺少依赖项: - React Hook useCallback has a missing dependency: React Hook useEffect/useCallback 缺少依赖项 - React Hook useEffect/useCallback has a missing dependency React Hook useCallback 缺少依赖项警告,但存在依赖项 - React Hook useCallback has a missing dependency warning, but the dependencies are present 修复 React Hook useEffect 缺少依赖项 - Fix React Hook useEffect has a missing dependency React Hook useEffect 缺少依赖项:'notes',如何修复? - React Hook useEffect has a missing dependency: 'notes', how to fix it? 如何修复 React Hook useEffect 缺少依赖项 - How to fix React Hook useEffect has a missing dependency 如何修复这个“React Hook useEffect has a missing dependency”警告? - How to fix this “React Hook useEffect has a missing dependency” warning? 如何解决此警告:“React Hook useEffect 缺少依赖项:'history'”? - How to fix this warning: “React Hook useEffect has a missing dependency: 'history'”? React Hook useCallback 有一个不必要的依赖:'GqlUserResponse' - React Hook useCallback has an unnecessary dependency: 'GqlUserResponse' Cube.js React Hook React.useCallback 缺少一个依赖项:'pivotConfig'。 + - Cube.js React Hook React.useCallback has a missing dependency: 'pivotConfig'. +
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM