useTheme hook provides a simple way to access the current theme colors based on the user’s color scheme preference (light or dark mode). It returns the appropriate color palette and a boolean indicating whether dark mode is active.
Usage
Return Value
The hook returns an object with two properties:The current theme color palette based on the active color scheme. Contains all color tokens defined in
Colors constant.Boolean indicating whether dark mode is currently active.
true when the user has dark mode enabled, false otherwise.Examples
Basic Styling
Conditional Rendering Based on Theme
Using Training Type Colors
When to Use
Styling Components
Use
useTheme to apply theme-aware colors to your components’ styles, ensuring they adapt to the user’s color scheme preference.Conditional Logic
Use the
isDark value for conditional rendering when you need different behavior or assets in light vs. dark mode.Dynamic Backgrounds
Use theme colors for backgrounds, borders, and other visual elements that should match the current theme.
Accessible Colors
Leverage the pre-defined color palette that ensures proper contrast ratios for text readability in both modes.
The
useTheme hook internally uses useColorScheme to detect the current color scheme and returns the corresponding color palette from the Colors constant.Related Hooks
useColorScheme
Get the raw color scheme value (“light” or “dark”)
useScreenOptions
Apply theme-aware navigation options to screens