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