fix: added cleanup when component unmount

This commit is contained in:
Juan Di Toro 2024-03-12 15:36:44 +01:00
parent 94406b7f13
commit 0ba128b135
1 changed files with 8 additions and 14 deletions

View File

@ -148,22 +148,16 @@ export function useUppy({
}) })
} }
setState("idle") setState("idle")
return () => {
// for (const event of ["complete", ...LISTENING_EVENTS]) {
// uppyInstance.current?.off(
// event as "complete" & keyof typeof LISTENING_EVENTS,
// //@ts-expect-error -- huh? typescript wtf
// setStateCb
// )
// }
// uppyInstance.current?.cancelAll({ reason: "unmount" })
// uppyInstance.current?.logout()
// uppyInstance.current?.close()
// uppyInstance.current = undefined
}
}, [targetRef, endpoint, uploader]) }, [targetRef, endpoint, uploader])
useEffect(() => {
return () => {
uppyInstance.current?.cancelAll({ reason: "unmount" })
uppyInstance.current?.logout()
uppyInstance.current?.close()
uppyInstance.current = undefined
}
}, [])
return { return {
getFiles: () => uppyInstance.current?.getFiles() ?? [], getFiles: () => uppyInstance.current?.getFiles() ?? [],
error: uppyInstance.current?.getState, error: uppyInstance.current?.getState,