sonner-native
Version:
An opinionated toast component for React Native. A port of @emilkowalski's sonner.
24 lines (23 loc) • 687 B
JavaScript
;
import React from 'react';
import { AppState } from 'react-native';
export const useAppStateListener = ({
onBackground,
onForeground
}) => {
const appState = React.useRef(AppState.currentState);
React.useEffect(() => {
const subscription = AppState.addEventListener('change', nextAppState => {
if ((appState.current === 'inactive' || appState.current === 'background') && nextAppState === 'active') {
onForeground();
} else {
onBackground();
}
appState.current = nextAppState;
});
return () => {
subscription.remove();
};
}, [onBackground, onForeground]);
};
//# sourceMappingURL=use-app-state.js.map