useThemeColor hook provides theme-aware color values that automatically adapt based on the current color scheme. It supports custom color overrides and falls back to predefined theme colors.
Function Signature
Parameters
The name of the color from the theme constants. Must be a valid key that exists in both
Colors.light and Colors.dark.Available values:'text'- Primary text color'background'- Background color'tint'- Accent/tint color'icon'- Icon color'tabIconDefault'- Inactive tab icon color'tabIconSelected'- Active tab icon color
Return Value
The resolved color string. Priority order:
- Custom color from
props.lightorprops.dark(based on current theme) - Theme color from
Colors[theme][colorName]
Usage
Basic Usage with Theme Colors
With Custom Color Overrides
Using Custom Colors
Multiple Theme Colors
Implementation Details
The hook internally usesuseColorScheme to determine the current theme and selects the appropriate color:
Theme Color Values
The default theme colors are defined in/constants/theme.ts:
Best Practices
- Use theme colors by default: Only provide custom colors when you need to override the theme
- Consistent naming: Use the same color names throughout your app for consistency
- Avoid hardcoded colors: Use this hook instead of hardcoding colors in styles
- Component composition: Create reusable themed components like
ThemedTextandThemedView
Source File
/hooks/use-theme-color.ts
Related
- useColorScheme - Detect current color scheme
- Theming - Theme color definitions and system overview
- Themed Components - Pre-built themed components