Skip to content

Commit

Permalink
fix: move useEffect up
Browse files Browse the repository at this point in the history
  • Loading branch information
nperez0111 committed Jun 26, 2024
1 parent 447ad5d commit 4c0f13e
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions packages/react/src/useEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,18 @@ function useEditor<TSelectorResult>(options: UseEditorOptions<TSelectorResult> =

useDebugValue(editor)

// This effect will handle creating/updating the editor instance
useEffect(() => {
if (!editor) {
// instantiate the editor if it doesn't exist
// for ssr, this is the first time the editor is created
editorInstance.create(options)
} else {
// if the editor does exist, update the editor options accordingly
editor.setOptions(options)
}
}, deps)

const {
onBeforeCreate,
onBlur,
Expand Down Expand Up @@ -297,18 +309,6 @@ function useEditor<TSelectorResult>(options: UseEditorOptions<TSelectorResult> =
}
}, [onBeforeCreate, onBlur, onCreate, onDestroy, onFocus, onSelectionUpdate, onTransaction, onUpdate, onContentError, editor])

// This effect will handle creating/updating the editor instance
useEffect(() => {
if (!editor) {
// instantiate the editor if it doesn't exist
// for ssr, this is the first time the editor is created
editorInstance.create(options)
} else {
// if the editor does exist, update the editor options accordingly
editor.setOptions(options)
}
}, deps)

/**
* Destroy the editor instance when the component completely unmounts
* As opposed to the cleanup function in the effect above, this will
Expand Down

0 comments on commit 4c0f13e

Please sign in to comment.