From 0dd23f9c5c54b5a5ebafce52c045a27d53323db3 Mon Sep 17 00:00:00 2001 From: Ryan Toronto Date: Wed, 15 Dec 2021 12:17:07 -0500 Subject: [PATCH] Make sure editor is available on first render --- packages/react/src/useEditor.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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(() => {