Something went wrong. Try again.
Bluesky app fork with some witchin' additions 💫 forked from jollywhoppers.com/witchsky.app
Something went wrong. Try again.
722 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 useOnAppStateChange(cb: (state: AppStateStatus) => void) { useEffect(() => { const sub = onAppStateChange(next => cb(next)) return () => sub.remove() }, [cb])}
export function useAppState() { const [state, setState] = useState(AppState.currentState) useOnAppStateChange(setState) return state}