简体   繁体   中英

How to properly fix React Hook useCallback has a missing dependency

I updated my Eslint rules using airbnb in my React typescript project.

I get those errors now:

React Hook useCallback has a missing dependency: 'setCookie'. Either include it or remove the dependency array.eslintreact-hooks/exhaustive-deps

I have this in the extend property inside 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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM