Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

eslint vscode plugin is not producing warnings for hooks

I created a react app with npx create-react-app my-app and did a yarn install. Added the following to App.js:

const a = () => 1,
  b = () => 2,
  c = () => 3;

function App() {
  const wut = useMemo(() => {
    return { a: a(), b: b(), c: c() };
  }, [a]);
  useEffect(() => {
    console.log(a(), b(), c());
  }, [a]);

Yarn start will give me warnings but vscode does not.

I added .eslintrc.js with the following content:

module.exports = {
  env: {
    browser: true,
    es6: true
  },
  extends: ["eslint:recommended", "plugin:react/recommended"],
  globals: {
    Atomics: "readonly",
    SharedArrayBuffer: "readonly"
  },
  parserOptions: {
    ecmaFeatures: {
      jsx: true
    },
    ecmaVersion: 2018,
    sourceType: "module"
  },
  plugins: ["react"],
  rules: {
    "react/prop-types": [0],
    "no-console": [0],
    "react-hooks/exhaustive-deps": "warn"
  }
};
like image 481
HMR Avatar asked Oct 31 '25 07:10

HMR


1 Answers

The list of rules for react/recommended doesn't include react-hooks/exhaustive-deps.

You likely didn't install eslint-plugin-react-hooks.

It includes a note:

Note: If you're using Create React App, please wait for a corresponding release of react-scripts that includes this rule instead of adding it directly.

What version of c-r-a are you using? In theory it was added via this PR.

like image 136
Dave Newton Avatar answered Nov 03 '25 04:11

Dave Newton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!