Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

fix: useEditor ref

shuaiab602ed001b9
diff --git a/ui/src/components/Editor/index.tsx b/ui/src/components/Editor/index.tsx
index 3756de0a..8fe0616e 100644
--- a/ui/src/components/Editor/index.tsx
+++ b/ui/src/components/Editor/index.tsx
@@ -66,13 +66,14 @@ const MDEditor: ForwardRefRenderFunction<EditorRef, Props> = (
const previewRef = useRef<{ getHtml; element } | null>(null);
const editor = useEditor({
- element: editorRef.current,
+ editorRef,
onChange,
onFocus,
onBlur,
placeholder: editorPlaceholder,
autoFocus,
});
+
const [markdown, setMarkdown] = useState<string>(value || '');
useEffect(() => {
diff --git a/ui/src/components/Editor/utils/index.ts b/ui/src/components/Editor/utils/index.ts
index a7f3cc3f..480ed0eb 100644
--- a/ui/src/components/Editor/utils/index.ts
+++ b/ui/src/components/Editor/utils/index.ts
@@ -120,7 +120,7 @@ export function htmlRender(el: HTMLElement | null) {
}
export const useEditor = ({
- element,
+ editorRef,
placeholder,
autoFocus,
onChange,
@@ -162,7 +162,7 @@ export const useEditor = ({
await import('codemirror/mode/markdown/markdown');
await import('codemirror/addon/display/placeholder');
- const cm = codeMirror(element, {
+ const cm = codeMirror(editorRef?.current, {
mode: 'markdown',
lineWrapping: true,
placeholder,
@@ -190,11 +190,11 @@ export const useEditor = ({
};
useEffect(() => {
- if (!(element instanceof HTMLElement)) {
+ if (!(editorRef.current instanceof HTMLElement)) {
return;
}
init();
- }, [element]);
+ }, [editorRef]);
return editor;
};
diff --git a/ui/src/components/PluginRender/index.tsx b/ui/src/components/PluginRender/index.tsx
index c4b7f886..b3a8efb8 100644
--- a/ui/src/components/PluginRender/index.tsx
+++ b/ui/src/components/PluginRender/index.tsx
@@ -1,4 +1,4 @@
-import React, { FC, ReactNode, memo } from 'react';
+import React, { FC, ReactNode } from 'react';
import PluginKit, { Plugin, PluginType } from '@/utils/pluginKit';
/**
@@ -54,7 +54,6 @@ const Index: FC<Props> = ({
if (type === 'editor') {
return <div className={className}>{children}</div>;
}
-
return null;
}
@@ -94,4 +93,4 @@ const Index: FC<Props> = ({
);
};
-export default memo(Index);
+export default Index;