From fd19fa9e5bca113ec76ead9f1c387d02764bf2a2 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 27 Nov 2023 14:56:42 -0600 Subject: [PATCH] FocusPlugin: refactor the useEffect for sanity --- src/features/compose/editor/plugins/focus-plugin.tsx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/features/compose/editor/plugins/focus-plugin.tsx b/src/features/compose/editor/plugins/focus-plugin.tsx index 65b567683..8a076f199 100644 --- a/src/features/compose/editor/plugins/focus-plugin.tsx +++ b/src/features/compose/editor/plugins/focus-plugin.tsx @@ -11,10 +11,6 @@ export const FOCUS_EDITOR_COMMAND: LexicalCommand = createCommand(); const FocusPlugin: React.FC = ({ autoFocus }) => { const [editor] = useLexicalComposerContext(); - const focus = () => { - editor.dispatchCommand(FOCUS_EDITOR_COMMAND, undefined); - }; - useEffect(() => editor.registerCommand(FOCUS_EDITOR_COMMAND, () => { editor.focus( () => { @@ -29,8 +25,10 @@ const FocusPlugin: React.FC = ({ autoFocus }) => { }, COMMAND_PRIORITY_NORMAL)); useEffect(() => { - if (autoFocus) focus(); - }, []); + if (autoFocus) { + editor.dispatchCommand(FOCUS_EDITOR_COMMAND, undefined); + } + }, [autoFocus, editor]); return null; };