diff --git a/packages/react/src/EditorContent.tsx b/packages/react/src/EditorContent.tsx index f65276f4d07..df40df31974 100644 --- a/packages/react/src/EditorContent.tsx +++ b/packages/react/src/EditorContent.tsx @@ -147,4 +147,14 @@ export class PureEditorContent extends React.Component { + const key = React.useMemo(() => { + return Math.floor(Math.random() * 0xFFFFFFFF).toString() + }, [props.editor]) + + // Can't use JSX here because it conflicts with the type definition of Vue's JSX, so use createElement + return React.createElement(PureEditorContent, { key, ...props }) +} + +export const EditorContent = React.memo(EditorContentWithKey) diff --git a/packages/react/src/useEditor.ts b/packages/react/src/useEditor.ts index fdede2825ea..2805eedec64 100644 --- a/packages/react/src/useEditor.ts +++ b/packages/react/src/useEditor.ts @@ -113,10 +113,15 @@ export const useEditor = (options: Partial = {}, deps: Dependency }) return () => { - instance.destroy() isMounted = false } }, deps) + useEffect(() => { + return () => { + editor?.destroy() + } + }, [editor]) + return editor }