From 42d61f7eb45cb6327fa5954caa3385cfc956365e Mon Sep 17 00:00:00 2001 From: Ryan Toronto Date: Thu, 16 Dec 2021 07:56:35 -0500 Subject: [PATCH] fix: Make sure editor is available on first render (#2282), fix #2040, fix #2182 --- src/useEditor.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/useEditor.ts b/src/useEditor.ts index 32896f235d..f42635de50 100644 --- a/src/useEditor.ts +++ b/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(() => {