Browse Source

refactor with useEffect

Yuken Tezuka 3 years ago
parent
commit
895ccec9b0
1 changed files with 7 additions and 7 deletions
  1. 7 7
      packages/app/src/components/PageEditor/Editor.tsx

+ 7 - 7
packages/app/src/components/PageEditor/Editor.tsx

@@ -73,13 +73,6 @@ const Editor: ForwardRefRenderFunction<IEditorMethods, EditorPropsType> = (props
   const cmEditorRef = useRef<AbstractEditor<any>>(null);
   const cmEditorRef = useRef<AbstractEditor<any>>(null);
   const taEditorRef = useRef<TextAreaEditor>(null);
   const taEditorRef = useRef<TextAreaEditor>(null);
 
 
-  useEffect(() => {
-    if (cmEditorRef.current != null) {
-      const editorNavBarItems = cmEditorRef.current.getNavbarItems() ?? [];
-      setNavBarItems(editorNavBarItems);
-    }
-  }, []);
-
   const editorSubstance = useCallback(() => {
   const editorSubstance = useCallback(() => {
     return isMobile ? taEditorRef.current : cmEditorRef.current;
     return isMobile ? taEditorRef.current : cmEditorRef.current;
   }, [isMobile]);
   }, [isMobile]);
@@ -267,6 +260,13 @@ const Editor: ForwardRefRenderFunction<IEditorMethods, EditorPropsType> = (props
     );
     );
   }, [isCheatsheetModalShown]);
   }, [isCheatsheetModalShown]);
 
 
+  useEffect(() => {
+    if (editorSubstance != null && editorSettings != null) {
+      const editorNavBarItems = editorSubstance()?.getNavbarItems() ?? [];
+      setNavBarItems(editorNavBarItems);
+    }
+  }, [editorSettings, editorSubstance]);
+
   if (editorSettings == null) {
   if (editorSettings == null) {
     return <></>;
     return <></>;
   }
   }