@criipto/verify-expo
Version:
Accept MitID, NemID, Swedish BankID, Norwegian BankID and more logins in your Expo (React-Native) app
23 lines • 872 B
JavaScript
import { useRef, useState, useEffect } from 'react';
import { AppState } from 'react-native';
export default function useAppState(onForeground, deps = []) {
const appState = useRef(AppState.currentState);
const [appStateVisible, setAppStateVisible] = useState(appState.current);
useEffect(() => {
const subscription = AppState.addEventListener('change', _handleAppStateChange);
return () => {
subscription.remove();
};
}, deps);
const _handleAppStateChange = (nextAppState) => {
if (appState.current.match(/inactive|background/) &&
nextAppState === 'active') {
if (onForeground)
onForeground();
}
appState.current = nextAppState;
setAppStateVisible(appState.current);
};
return appStateVisible;
}
//# sourceMappingURL=useAppState.js.map