import { useCallback , useEffect , useState } from 'react' ; import { BrightnessMode , getSystemBrightnessModeAsync , setSystemBrightnessModeAsync } from 'expo-brightness' ; see https remarks example export function useSystemBrightnessMode ( options = { } ) { const [ data , setData ] = useState < BrightnessMode > ( ) ; const { get = true } = options ; const setSystemBrightnessMode = useCallback ( ( mode ) => ( setSystemBrightnessModeAsync ( mode ) . then ( ( ) => setData ( mode ) ) ) , [ ] ) ; const getSystemBrightnessMode = useCallback ( ( ) => ( getSystemBrightnessModeAsync ( ) . then ( setData ) ) , [ setData ] ) ; useEffect ( ( ) => { if ( get ) { getSystemBrightnessMode ( ) ; } } , [ get , getSystemBrightnessMode ] ) ; return [ data , setSystemBrightnessMode , getSystemBrightnessMode ] ; } export interface SystemBrightnessModeOptions { /** If it should fetch the brightness mode when mounted, defaults to `true` */ get ? : boolean ; }