Fix state update after component unmounted (#2857)

Co-authored-by: Andrii Savluk <a.savluk@ideil.com>
This commit is contained in:
SavKS 2022-06-24 18:46:54 +03:00 committed by GitHub
parent e4a81c1460
commit 8e65c20815
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)