瀏覽代碼

feat: eslint添加hooks规则

lanjianrong 4 年之前
父節點
當前提交
e8aac41109
共有 3 個文件被更改,包括 12 次插入12 次删除
  1. 4 3
      .eslintrc
  2. 2 3
      package.json
  3. 6 6
      src/pages/Safe/Content/Info/Summary/index.tsx

+ 4 - 3
.eslintrc

@@ -16,15 +16,16 @@
     "ecmaVersion": 2018,
     "sourceType": "module"
   },
-  "plugins": ["react", "@typescript-eslint"],
+  "plugins": ["react", "@typescript-eslint", "react-hooks"],
   "rules": {
     "semi": ["error", "never"],
     "no-multiple-empty-lines": [1, { "max": 2 }], //空行最多不能超过2行
     "comma-dangle": [2, "never"],
     "react/prop-types": 0,
     "array-bracket-spacing": ["error", "always"],
-    "object-curly-spacing": ["error", "always"]
-
+    "object-curly-spacing": ["error", "always"],
+    "react-hooks/rules-of-hooks": "error"
+    // "react-hooks/exhaustive-deps": "warn"
     // "import/no-unresolved": [1, { "ignore": ["^@/"] }]
   },
   "settings": {

+ 2 - 3
package.json

@@ -130,7 +130,7 @@
     "eslint-plugin-import": "2.20.1",
     "eslint-plugin-jsx-a11y": "6.2.3",
     "eslint-plugin-react": "^7.20.6",
-    "eslint-plugin-react-hooks": "^1.6.1",
+    "eslint-plugin-react-hooks": "^1.7.0",
     "file-loader": "4.3.0",
     "fs-extra": "^8.1.0",
     "html-webpack-plugin": "4.0.0-beta.11",
@@ -174,8 +174,7 @@
     "webpack": "4.42.0",
     "webpack-dev-server": "3.11.0",
     "webpack-manifest-plugin": "2.2.0",
-    "workbox-webpack-plugin": "4.3.1",
-    "@types/echarts": "^4.9.3"
+    "workbox-webpack-plugin": "4.3.1"
   },
   "dependencies": {
     "@ant-design/charts": "^1.0.13",

+ 6 - 6
src/pages/Safe/Content/Info/Summary/index.tsx

@@ -35,12 +35,6 @@ interface iSummaryState {
   lineData: SafeLineChartType[]
 }
 const Summary: React.FC<{}> = () => {
-  useEffect(() => {
-    initData()
-  }, [])
-  useActivate(() => {
-    initData()
-  })
   const [ state, setState ] = useState<iSummaryState>({
     approvalTotal: 0,
     rectifyTotal: 0,
@@ -49,6 +43,12 @@ const Summary: React.FC<{}> = () => {
     columnarData: [],
     lineData: []
   })
+  useEffect(() => {
+    initData()
+  }, [ tenderStore.bid ])
+  useActivate(() => {
+    initData()
+  })
   useActivate(() => initData())
   const initData = async () => {
     const { data, code = -1 } = await apiGetSafeSurvey(tenderStore.bid)