import { useEffect , useState } from 'react' ; import { AppStateStatus , AppState } from 'react-native' ; export function useAppState ( ) { const [ state , setState ] = useState < AppStateStatus > ( AppState . currentState ) ; const handler = ( nextState ) => { setState ( nextState ) ; } ; useEffect ( ( ) => { AppState . addEventListener ( 'change' , handler ) ; return ( ) => { AppState . removeEventListener ( 'change' , handler ) ; } ; } , [ ] ) ; return [ state ] ; }