Skip to content

Commit

Permalink
fix: unify props setting to avoid composition errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyaGurevich committed Sep 11, 2023
1 parent 64dd486 commit fa41fa1
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions src/hooks/useEditorView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,11 @@ export function useEditorView<T extends HTMLElement = HTMLElement>(

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) {
Expand Down Expand Up @@ -117,12 +109,8 @@ export function useEditorView<T extends HTMLElement = HTMLElement>(
}, [editorProps, mount, state, view]);

useLayoutEffect(() => {
view?.setProps(nonStateProps);
}, [view, nonStateProps]);

useLayoutEffect(() => {
if (stateProp) view?.setProps({ state: stateProp });
}, [view, stateProp]);
view?.setProps(editorProps);
}, [view, editorProps]);

return view;
}

0 comments on commit fa41fa1

Please sign in to comment.