import { useCallback , useEffect , useState } from 'react' ; import { getBrightnessAsync , setBrightnessAsync } from 'expo-brightness' ; see https remarks example export function useBrightness ( options = { } ) { const [ data , setData ] = useState < number > ( ) ; const { get = true } = options ; const setBrightness = useCallback ( ( brightness ) => ( setBrightnessAsync ( brightness ) . then ( ( ) => setData ( brightness ) ) ) , [ setData ] ) ; const getBrightness = useCallback ( ( ) => ( getBrightnessAsync ( ) . then ( setData ) ) , [ setData ] ) ; useEffect ( ( ) => { if ( get ) { getBrightness ( ) ; } } , [ get , getBrightness ] ) ; return [ data , setBrightness , getBrightness ] ; } export interface BrightnessOptions { /** If it should fetch the brightness when mounted, defaults to `true` */ get ? : boolean ; }