Sfoglia il codice sorgente

:fire: useEffect wordInput

visuddhinanda 2 anni fa
parent
commit
460f33ceaf
1 ha cambiato i file con 9 aggiunte e 9 eliminazioni
  1. 9 9
      dashboard/src/components/dict/Dictionary.tsx

+ 9 - 9
dashboard/src/components/dict/Dictionary.tsx

@@ -23,7 +23,7 @@ const DictionaryWidget = ({ word, compact = false, onSearch }: IWidget) => {
 
 
   useEffect(() => {
   useEffect(() => {
     console.debug("param word change", word);
     console.debug("param word change", word);
-    setWordInput(word);
+    wordInputChange(word);
   }, [word]);
   }, [word]);
 
 
   const wordChange = (value?: string) => {
   const wordChange = (value?: string) => {
@@ -57,22 +57,22 @@ const DictionaryWidget = ({ word, compact = false, onSearch }: IWidget) => {
     return currWord;
     return currWord;
   };
   };
 
 
-  useEffect(() => {
-    console.debug("wordInput change", wordInput);
-    if (wordInput !== wordSearch) {
-      const currWord = wordChange(wordInput);
+  const wordInputChange = (value: string | undefined) => {
+    setWordInput(value);
+    console.debug("wordInput change", value);
+    if (value !== wordSearch) {
+      const currWord = wordChange(value);
       setWordSearch(currWord);
       setWordSearch(currWord);
     }
     }
-  }, [wordInput]);
+  };
 
 
   const dictSearch = (value: string, isFactor?: boolean) => {
   const dictSearch = (value: string, isFactor?: boolean) => {
     console.info("onSearch", value);
     console.info("onSearch", value);
     const currWord = wordChange(value);
     const currWord = wordChange(value);
     if (typeof onSearch !== "undefined" && !isFactor) {
     if (typeof onSearch !== "undefined" && !isFactor) {
       onSearch(currWord);
       onSearch(currWord);
-    } else {
-      setWordSearch(currWord);
     }
     }
+    setWordSearch(currWord);
   };
   };
   return (
   return (
     <div ref={setContainer}>
     <div ref={setContainer}>
@@ -127,7 +127,7 @@ const DictionaryWidget = ({ word, compact = false, onSearch }: IWidget) => {
                   if (typeof onSearch !== "undefined") {
                   if (typeof onSearch !== "undefined") {
                     onSearch(newInput);
                     onSearch(newInput);
                   } else {
                   } else {
-                    setWordInput(newInput);
+                    wordInputChange(newInput);
                   }
                   }
                 }}
                 }}
               />
               />