fix: Fix AppState.removeListener warning by using new API (#419)

* refactor: suppress AppState.removeListener warning by deprecation

AppState.AddEventListener returns a remove function subscription,
which replaces the removeListener method

* fix: Property 'remove' does not exist on type 'void'

* chore: add missing trailing comma

* chore: update react-native static types version
This commit is contained in:
Antonio Sousa
2021-09-22 08:25:15 -03:00
committed by GitHub
parent ffb4a188a2
commit 1a4fd7a233
3 changed files with 13 additions and 4 deletions

View File

@@ -9,8 +9,10 @@ export const useIsForeground = (): boolean => {
const onChange = (state: AppStateStatus): void => {
setIsForeground(state === 'active');
};
AppState.addEventListener('change', onChange);
return () => AppState.removeEventListener('change', onChange);
const subscription = AppState.addEventListener('change', onChange);
return () => {
subscription.remove();
};
}, [setIsForeground]);
return isForeground;