Skip to content

Commit

Permalink
Merge pull request #5359 from enagorny/fix-deprecated-removeEventList…
Browse files Browse the repository at this point in the history
…ener

fix: warning on RN v0.65+
  • Loading branch information
rayan1810 authored Oct 31, 2022
2 parents 6973ace + 4382388 commit 45bd6b2
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/core/color-mode/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,17 @@ export const useAppState = () => {
() => ({
getCurrentValue: () => AppState.currentState,
subscribe: (callback: () => void) => {
AppState.addEventListener('change', callback);
return () => AppState.removeEventListener('change', callback);
const subsription = AppState.addEventListener('change', callback);
return () => {
if (AppState.removeEventListener) {
// 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();
}
};
},
}),
[]
Expand Down

0 comments on commit 45bd6b2

Please sign in to comment.