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(); } }; },