Install
Terminal
npm install --save-dev eslint-plugin-react-hooks @eslint-react/eslint-pluginSetup
.eslintrc.js
module.exports = {
root: true,
env: { browser: true, es2021: true },
parser: "@typescript-eslint/parser",
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react-hooks/recommended",
"plugin:@eslint-react/recommended-legacy",
],
plugins: ["@typescript-eslint", "react-hooks"],
ignorePatterns: ["dist", ".eslintrc.js"],
};Linting with type information
Rules that require type information are not enabled by default. To enable them, you need to set the project option in parserOptions to the path of your tsconfig.json file.
Then replace plugin:@eslint-react/recommended-legacy with plugin:@eslint-react/recommended-type-checked-legacy.
.eslintrc.js
module.exports = {
root: true,
env: { browser: true, es2021: true },
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: "2021",
sourceType: "module",
project: "./tsconfig.json", // <-- Point to your project's "tsconfig.json" or create a new one.
},
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react-hooks/recommended",
"plugin:@eslint-react/recommended-legacy",
],
plugins: ["@typescript-eslint", "react-hooks"],
ignorePatterns: ["dist", ".eslintrc.js"],
};