我正在尝试安装eslint插件以进行反应挂钩,但似乎无法使其正常工作。在此先感谢您的帮助!
这是我所做的以及如何对其进行测试:
npm install eslint-plugin-react-hooks --save-dev
//package.json:
{
"name": "askify-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^1.2.25",
"@fortawesome/free-brands-svg-icons": "^5.11.2",
"@fortawesome/free-solid-svg-icons": "^5.11.2",
"@fortawesome/react-fontawesome": "^0.1.7",
"now": "^16.6.0",
"react": "^16.12.0",
"react-devtools": "^4.2.1",
"react-dom": "^16.12.0",
"react-router-dom": "^5.1.2",
"react-scripts": "3.2.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app",
"plugins": [
"react-hooks"
],
"rules": {
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn"
}
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"eslint-plugin-react-hooks": "^2.3.0",
"react-test-renderer": "^16.12.0"
}
}
我正在通过将以下代码添加到我的app.js并期望它显示错误并为[props.name]提供自动修复的功能来进行测试
function Foo(props) {
useEffect(() => {
console.log(props.name);
}, [])
}