import { useCallback , useEffect , useState } from 'react' ; import { isLowPowerModeEnabledAsync , addLowPowerModeListener } from 'expo-battery' ; see https remarks example export function useBatteryLowPowerMode ( options = { } ) { const [ data , setData ] = useState < boolean > ( ) ; const { get = true , listen = true , } = options ; const getBatteryLowPowerMode = useCallback ( ( ) => ( isLowPowerModeEnabledAsync ( ) . then ( setData ) ) , [ ] ) ; useEffect ( ( ) => { if ( get ) { getBatteryLowPowerMode ( ) ; } if ( listen ) { return addLowPowerModeListener ( state => setData ( state . lowPowerMode ) ) . remove ; } } , [ get , getBatteryLowPowerMode , listen ] ) ; return [ data , getBatteryLowPowerMode ] ; } export interface BatteryLowPowerModeOptions { /** If it should fetch the battery low power mode status when mounted, defaults to `true` */ get ? : boolean ; /** If it should listen to any change in battery low power mode status, defaults to `true` */ listen ? : boolean ; }