Fix state update after component unmounted (#2857)
Co-authored-by: Andrii Savluk <a.savluk@ideil.com>
This commit is contained in:
@@ -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(() => {
|
||||
if (isMounted) {
|
||||
forceUpdate()
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
return () => {
|
||||
instance.destroy()
|
||||
isMounted = false
|
||||
}
|
||||
}, deps)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user