From 0ba128b135b39ef5fceceba588bb60c123b14114 Mon Sep 17 00:00:00 2001 From: Juan Di Toro Date: Tue, 12 Mar 2024 15:36:44 +0100 Subject: [PATCH] fix: added cleanup when component unmount --- app/components/lib/uppy.ts | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/app/components/lib/uppy.ts b/app/components/lib/uppy.ts index 9c06abb..147fe04 100644 --- a/app/components/lib/uppy.ts +++ b/app/components/lib/uppy.ts @@ -148,22 +148,16 @@ export function useUppy({ }) } 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]) + useEffect(() => { + return () => { + uppyInstance.current?.cancelAll({ reason: "unmount" }) + uppyInstance.current?.logout() + uppyInstance.current?.close() + uppyInstance.current = undefined + } + }, []) return { getFiles: () => uppyInstance.current?.getFiles() ?? [], error: uppyInstance.current?.getState,