From 2a19fb5e36be3a212237e72b7d2cded52197ef66 Mon Sep 17 00:00:00 2001 From: Ilya Gurevich Date: Mon, 11 Sep 2023 17:08:39 -0400 Subject: [PATCH] state props before non-state props --- src/hooks/useEditorView.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/hooks/useEditorView.ts b/src/hooks/useEditorView.ts index e18ba24d..ca019493 100644 --- a/src/hooks/useEditorView.ts +++ b/src/hooks/useEditorView.ts @@ -71,11 +71,19 @@ export function useEditorView( const editorProps = withFlushedDispatch(props, forceUpdate); + const stateProp = "state" in editorProps ? editorProps.state : undefined; + const state = "defaultState" in editorProps ? editorProps.defaultState : editorProps.state; + const nonStateProps = Object.fromEntries( + Object.entries(editorProps).filter( + ([propName]) => propName !== "state" && propName !== "defaultState" + ) + ); + useLayoutEffect(() => { return () => { if (view) { @@ -109,8 +117,12 @@ export function useEditorView( }, [editorProps, mount, state, view]); useLayoutEffect(() => { - view?.setProps(editorProps); - }, [view, editorProps]); + if (stateProp) view?.setProps({ state: stateProp }); + }, [view, stateProp]); + + useLayoutEffect(() => { + view?.setProps(nonStateProps); + }, [view, nonStateProps]); return view; }