From 40f49a7dbe99529aeaede96d7526ed570cf934b5 Mon Sep 17 00:00:00 2001 From: Sascha Kurth Date: Tue, 18 Apr 2023 17:31:02 +0200 Subject: [PATCH] fix: prevent unnecessary AppState warning on some react-native versions --- src/core/color-mode/hooks.tsx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/core/color-mode/hooks.tsx b/src/core/color-mode/hooks.tsx index cab1f709c..bc82d9deb 100644 --- a/src/core/color-mode/hooks.tsx +++ b/src/core/color-mode/hooks.tsx @@ -33,15 +33,16 @@ export const useAppState = () => { () => ({ getCurrentValue: () => AppState.currentState, subscribe: (callback: () => void) => { - const subsription = AppState.addEventListener('change', callback); + const subscription = AppState.addEventListener('change', callback); + return () => { - if (AppState.removeEventListener) { + if (Object.prototype.hasOwnProperty.call(subscription, 'remove')) { + // React Native >= 0.65 + /* @ts-ignore ignoring ts error as devDependency contains "@types/react-native" < 0.65 */ + subscription.remove(); + } else { // React Native < 0.65 AppState.removeEventListener('change', callback); - } else { - // React Native >= 0.65 - // @ts-ignore:next-line ignoring ts error as devDependency contains "@types/react-native" < 0.65 - subsription.remove(); } }; },