mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-18 22:36:14 +08:00
Fix state update after component unmounted (#2857)
Co-authored-by: Andrii Savluk <a.savluk@ideil.com>
This commit is contained in:
parent
e4a81c1460
commit
8e65c20815
@ -14,6 +14,8 @@ export const useEditor = (options: Partial<EditorOptions> = {}, deps: Dependency
|
||||
const forceUpdate = useForceUpdate()
|
||||
|
||||
useEffect(() => {
|
||||
let isMounted = true
|
||||
|
||||
const instance = new Editor(options)
|
||||
|
||||
setEditor(instance)
|
||||
@ -21,13 +23,16 @@ export const useEditor = (options: Partial<EditorOptions> = {}, deps: Dependency
|
||||
instance.on('transaction', () => {
|
||||
requestAnimationFrame(() => {
|
||||
requestAnimationFrame(() => {
|
||||
forceUpdate()
|
||||
if (isMounted) {
|
||||
forceUpdate()
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
return () => {
|
||||
instance.destroy()
|
||||
isMounted = false
|
||||
}
|
||||
}, deps)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user