HMR*_*HMR 4 reactjs eslint visual-studio-code create-react-app
我创建了一个反应应用程序并npx create-react-app my-app进行了纱线安装。在 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]);
Run Code Online (Sandbox Code Playgroud)
Yarn start 会给我警告,但 vscode 不会。
我添加.eslintrc.js了以下内容:
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"
}
};
Run Code Online (Sandbox Code Playgroud)
的规则列表react/recommended不包括react-hooks/exhaustive-deps.
您可能没有安装eslint-plugin-react-hooks。
它包括一个注释:
注意:如果您使用的是Create React App,请等待包含此规则的react-scripts的相应版本,而不是直接添加它。
你用的cra是什么版本?理论上它是通过此 PR添加的。
| 归档时间: |
|
| 查看次数: |
7397 次 |
| 最近记录: |