about summary refs log tree commit diff
path: root/src/lib/hooks/useAppState.ts
blob: 7fb228d61861293cf9460f0cb4a949cea48f53f9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import {useEffect, useState} from 'react'
import {AppState} from 'react-native'

export function useAppState() {
  const [state, setState] = useState(AppState.currentState)

  useEffect(() => {
    const sub = AppState.addEventListener('change', nextAppState => {
      setState(nextAppState)
    })
    return () => sub.remove()
  }, [])

  return state
}