From d2eee24995f0f4c213ae3b1087bf2525fea220a4 Mon Sep 17 00:00:00 2001 From: Avo Date: Tue, 8 Jun 2021 13:46:24 +0300 Subject: [PATCH] Cancel InteractionManager's task on unmount Fix for this warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function --- src/useInteractionManager.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/useInteractionManager.ts b/src/useInteractionManager.ts index 1317f19c..c3be940c 100644 --- a/src/useInteractionManager.ts +++ b/src/useInteractionManager.ts @@ -5,9 +5,14 @@ export function useInteractionManager() { const [complete, updateInteractionStatus] = useState(false) useEffect(() => { - InteractionManager.runAfterInteractions(() => { + const {cancel} = InteractionManager.runAfterInteractions(() => { updateInteractionStatus(true) }) + + return () => { + cancel?.() + } }, []) + return complete }