Просмотр исходного кода

unable to push template button if receive editor as null

soumaeda 2 лет назад
Родитель
Сommit
603fd81139

+ 5 - 3
packages/editor/src/components/CodeMirrorEditor/Toolbar/TemplateButton.tsx

@@ -14,9 +14,11 @@ export const TemplateButton = (props: Props): JSX.Element => {
 
   const onClickTempleteButton = useCallback(() => {
     const editor = codeMirrorEditor?.view;
-    const insertText = (text: string) => editor?.dispatch(editor.state.replaceSelection(text));
-    const onSubmit = (templateText: string) => insertText(templateText);
-    openTemplateModal({ onSubmit });
+    if (editor != null) {
+      const insertText = (text: string) => editor.dispatch(editor.state.replaceSelection(text));
+      const onSubmit = (templateText: string) => insertText(templateText);
+      openTemplateModal({ onSubmit });
+    }
   }, [codeMirrorEditor?.view, openTemplateModal]);
 
   return (