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:
@@ -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;
|
||||
|
Reference in New Issue
Block a user