From d6ad42f10c085d841535540ee5c9db62dc25e789 Mon Sep 17 00:00:00 2001 From: Karol Firmanty Date: Tue, 12 Mar 2024 20:23:01 +0100 Subject: [PATCH] fix editor cleanup --- packages/react/src/useEditor.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/packages/react/src/useEditor.ts b/packages/react/src/useEditor.ts index e80ca4a49a3..94f73ea0e3b 100644 --- a/packages/react/src/useEditor.ts +++ b/packages/react/src/useEditor.ts @@ -99,7 +99,8 @@ export const useEditor = (options: Partial = {}, deps: Dependency useEffect(() => { let isMounted = true - editorRef.current = new Editor(options) + const editor = new Editor(options) + editorRef.current = editor editorRef.current.on('transaction', () => { requestAnimationFrame(() => { @@ -113,14 +114,9 @@ export const useEditor = (options: Partial = {}, deps: Dependency return () => { isMounted = false + editor.destroy() } }, deps) - useEffect(() => { - return () => { - return editorRef.current?.destroy() - } - }, []) - return editorRef.current }