Skip to content

Commit

Permalink
fix: Make sure editor is available on first render (ueberdosis#2282), f…
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanto committed Dec 16, 2021
1 parent 15f29bf commit 42d61f7
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/useEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ function useForceUpdate() {
}

export const useEditor = (options: Partial<EditorOptions> = {}, deps: DependencyList = []) => {
const [editor, setEditor] = useState<Editor | null>(null)
const [editor, setEditor] = useState<Editor>(() => new Editor(options))
const forceUpdate = useForceUpdate()

useEffect(() => {
const instance = new Editor(options)
let instance: Editor

setEditor(instance)
if (editor.isDestroyed) {
instance = new Editor(options)
setEditor(instance)
} else {
instance = editor
}

instance.on('transaction', () => {
requestAnimationFrame(() => {
Expand Down

0 comments on commit 42d61f7

Please sign in to comment.