diff --git a/dist/index.js b/dist/index.js index 1200bee..550235f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,5 +1,5 @@ -import { useState, useEffect } from 'react'; -import { AppState } from 'react-native'; +import { useState, useEffect } from "react"; +import { AppState } from "react-native"; export default function useAppState(settings) { const { onChange, onForeground, onBackground } = settings || {}; @@ -7,22 +7,25 @@ export default function useAppState(settings) { useEffect(() => { function handleAppStateChange(nextAppState) { - if (nextAppState === 'active' && appState !== 'active') { + if (nextAppState === "active" && appState !== "active") { isValidFunction(onForeground) && onForeground(); - } else if (appState === 'active' && nextAppState.match(/inactive|background/)) { + } else if ( + appState === "active" && + nextAppState.match(/inactive|background/) + ) { isValidFunction(onBackground) && onBackground(); } setAppState(nextAppState); isValidFunction(onChange) && onChange(nextAppState); } - const appState = AppState.addEventListener('change', handleAppStateChange); + const appState = AppState.addEventListener("change", handleAppStateChange); - return () => appState.remove(); + return () => appState?.remove(); }, [onChange, onForeground, onBackground, appState]); // settings validation function isValidFunction(func) { - return func && typeof func === 'function'; + return func && typeof func === "function"; } return { appState }; }