mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-06-11 20:08:59 +08:00
fix(react): useEditor hook now respects deps array and will re-initialize editor (#5353)
This commit is contained in:
parent
a473826eb1
commit
70eebfdb0c
5
.changeset/curly-buses-attend.md
Normal file
5
.changeset/curly-buses-attend.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@tiptap/react": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
The optional deps argument to useEditor was not being respected for performance optimizations, now if deps are declared a new editor instance is created
|
@ -104,9 +104,15 @@ export function useEditor(
|
|||||||
editorInstance = new Editor(options)
|
editorInstance = new Editor(options)
|
||||||
// instantiate the editor if it doesn't exist
|
// instantiate the editor if it doesn't exist
|
||||||
// for ssr, this is the first time the editor is created
|
// for ssr, this is the first time the editor is created
|
||||||
|
setEditor(editorInstance)
|
||||||
|
} else if (Array.isArray(deps) && deps.length) {
|
||||||
|
// the deps array is used to re-initialize the editor instance
|
||||||
|
editorInstance = new Editor(options)
|
||||||
|
|
||||||
setEditor(editorInstance)
|
setEditor(editorInstance)
|
||||||
} else {
|
} else {
|
||||||
// if the editor does exist, update the editor options accordingly
|
// if the editor does exist & deps are empty, we don't need to re-initialize the editor
|
||||||
|
// we can fast-path to update the editor options on the existing instance
|
||||||
editorInstance.setOptions(options)
|
editorInstance.setOptions(options)
|
||||||
}
|
}
|
||||||
}, deps)
|
}, deps)
|
||||||
|
Loading…
Reference in New Issue
Block a user