Something went wrong. Try again.
Bluesky app fork with some witchin' additions 💫 forked from jollywhoppers.com/witchsky.app
Something went wrong. Try again.
632 B · 26 lines
TypeScript
at main
123456789101112131415161718192021222324252627import {useEffect, useState} from 'react'import {AppState, type AppStateStatus} from 'react-native'
export const getCurrentState = () => AppState.currentState
export function onAppStateChange(cb: (state: AppStateStatus) => void) { let prev = AppState.currentState return AppState.addEventListener('change', next => { if (next === prev) return prev = next cb(next) })}
export function useAppState() { const [state, setState] = useState(AppState.currentState)
useEffect(() => { const sub = onAppStateChange(next => { setState(next) }) return () => sub.remove() }, [])
return state}