Explorar el Código

Wrap GraphViewer when passing into state

Taichi Masuyama hace 3 años
padre
commit
1c0bf47396
Se han modificado 1 ficheros con 4 adiciones y 8 borrados
  1. 4 8
      packages/app/src/components/Drawio.tsx

+ 4 - 8
packages/app/src/components/Drawio.tsx

@@ -39,7 +39,9 @@ const Drawio = (props: Props): JSX.Element => {
 
 
   const { t } = useTranslation();
   const { t } = useTranslation();
 
 
-  const [GraphViewer, setGraphViewer] = useState<IGraphViewer | undefined>(undefined);
+  // Wrap with a function since GraphViewer is a function.
+  // This applies when call setGraphViewer as well.
+  const [GraphViewer, setGraphViewer] = useState<IGraphViewer | undefined>(() => (window as CustomWindow).GraphViewer);
 
 
   const { drawioContent, rangeLineNumberOfMarkdown, isPreview } = props;
   const { drawioContent, rangeLineNumberOfMarkdown, isPreview } = props;
 
 
@@ -74,15 +76,9 @@ const Drawio = (props: Props): JSX.Element => {
   const renderDrawioWithDebounce = useMemo(() => debounce(200, renderDrawio), [renderDrawio]);
   const renderDrawioWithDebounce = useMemo(() => debounce(200, renderDrawio), [renderDrawio]);
 
 
   useEffect(() => {
   useEffect(() => {
-    setGraphViewer(() => (window as CustomWindow).GraphViewer);
-  }, []);
-
-  useEffect(() => {
-    console.log('USE EFFECT', GraphViewer);
     if (GraphViewer == null) {
     if (GraphViewer == null) {
       waitForGraphViewer((gv: IGraphViewer) => {
       waitForGraphViewer((gv: IGraphViewer) => {
-        console.log('SET', gv);
-        setGraphViewer(gv);
+        setGraphViewer(() => gv);
       });
       });
       return;
       return;
     }
     }