/ SiPPP / hooks / useThemeColor.ts
useThemeColor.ts
 1  /**
 2   * Learn more about light and dark modes:
 3   * https://docs.expo.dev/guides/color-schemes/
 4   */
 5  
 6  import { useColorScheme } from 'react-native';
 7  
 8  import { Colors } from '@/constants/Colors';
 9  
10  export function useThemeColor(
11    props: { light?: string; dark?: string },
12    colorName: keyof typeof Colors.light & keyof typeof Colors.dark
13  ) {
14    const theme = useColorScheme() ?? 'light';
15    const colorFromProps = props[theme];
16  
17    if (colorFromProps) {
18      return colorFromProps;
19    } else {
20      return Colors[theme][colorName];
21    }
22  }