Reputation: 7642
I have a .eslintrc
file with the following rules:
"rules": {
"prettier/prettier": "error",
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "error",
"no-console": "warn"
},
I've installed: eslint-plugin-prettier
, eslint-config-prettier
and eslint-plugin-react-hooks
I've enabled "eslint.validate": [ "javascript", "javascriptreact", "html", "typescriptreact" ],
in settings.json in vscode
but when I remove dependencies that are needed in a useEffect
, it's not showing an error that I hoped it would
what else do I need to do?
Upvotes: 7
Views: 7793
Reputation: 81
I use react 18.2.0 , react-scripts 5.0.1 and react-app-rewired 2.2.1.
You must to add some code in .eslintrc
.
{
"plugins": [
// ...
"react-hooks" // for activate eslint checking react hooks
],
"rules": {
// ...
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "error"
}
}
Upvotes: 8
Reputation: 7642
This worked for me only when I updated react-scripts
to 4.x.x
It also helps to restart the ESLint server in VScode after doing this
hgb123
answer also is useful if you haven't already done that
Upvotes: 0
Reputation: 14891
In .eslintrc
, along with to adding rules
, you must add react-hooks
in the list of plugins
{
"plugins": [
// ...
"react-hooks"
],
"rules": {
// ...
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "error"
}
}
Upvotes: 2