diff --git a/packages/react/src/useEditor.ts b/packages/react/src/useEditor.ts index 32896f235db..f42635de509 100644 --- a/packages/react/src/useEditor.ts +++ b/packages/react/src/useEditor.ts @@ -9,13 +9,18 @@ function useForceUpdate() { } export const useEditor = (options: Partial = {}, deps: DependencyList = []) => { - const [editor, setEditor] = useState(null) + const [editor, setEditor] = useState(() => new Editor(options)) const forceUpdate = useForceUpdate() useEffect(() => { - const instance = new Editor(options) + let instance: Editor - setEditor(instance) + if (editor.isDestroyed) { + instance = new Editor(options) + setEditor(instance) + } else { + instance = editor + } instance.on('transaction', () => { requestAnimationFrame(() => {