Browse Source

add description for react-hooks/exhaustive-deps

czhen 4 years ago
parent
commit
84731b0844

+ 2 - 0
client/src/components/advancedSearch/Condition.tsx

@@ -104,6 +104,7 @@ const Condition: FC<ConditionProps> = props => {
       isCorrect: isValuelegal,
       id,
     });
+    // No need of 'id', 'isValuelegal', and 'triggerChange'.
     // eslint-disable-next-line react-hooks/exhaustive-deps
   }, [conditionField, operator, conditionValue]);
 
@@ -116,6 +117,7 @@ const Condition: FC<ConditionProps> = props => {
       isCorrect: isValuelegal,
       id,
     });
+    // No need of 'id', 'isValuelegal', and 'triggerChange'.
     // eslint-disable-next-line react-hooks/exhaustive-deps
   }, [isValuelegal]);
 

+ 1 - 0
client/src/components/advancedSearch/Dialog.tsx

@@ -38,6 +38,7 @@ const AdvancedDialog = (props: DialogProps) => {
 
   useEffect(() => {
     flatConditions.length === 0 && addCondition();
+    // Only need add one condition after dialog's first mount.
     // eslint-disable-next-line react-hooks/exhaustive-deps
   }, []);
 

+ 5 - 6
client/src/components/advancedSearch/Filter.tsx

@@ -43,10 +43,10 @@ const Filter = function Filter(props: FilterProps) {
   const [isConditionsLegal, setIsConditionsLegal] = useState(false);
   const [filterExpression, setFilterExpression] = useState('');
 
-  useEffect(() => {
-    setInitConditions(flatConditions);
-    // eslint-disable-next-line react-hooks/exhaustive-deps
-  }, []);
+  // useEffect(() => {
+  //   setInitConditions(flatConditions);
+  //   // eslint-disable-next-line react-hooks/exhaustive-deps
+  // }, []);
 
   // Check all conditions are all correct.
   useEffect(() => {
@@ -69,8 +69,7 @@ const Filter = function Filter(props: FilterProps) {
       }
     }
     setIsConditionsLegal(true);
-    generateExpression(flatConditions, setFilterExpression);
-    // eslint-disable-next-line react-hooks/exhaustive-deps
+    generateExpression(flatConditions, setFilterExpression);    
   }, [flatConditions]);
 
   const setFilteredFlatConditions = (conditions: any[]) => {