mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-23 19:19:03 +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)
|
||||
// instantiate the editor if it doesn't exist
|
||||
// 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)
|
||||
} 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)
|
||||
}
|
||||
}, deps)
|
||||
|
Loading…
Reference in New Issue
Block a user