useColorScheme hook detects the current color scheme preference of the user’s device. It returns either 'light', 'dark', or null if the color scheme cannot be determined.
Platform Differences
This hook has different implementations for native and web platforms:- Native (iOS/Android): Directly exports React Native’s
useColorSchemehook - Web: Implements hydration-aware logic to support static rendering
Web Implementation
On web, the hook includes special handling for server-side rendering and static site generation:'light' during SSR and updating after client-side hydration.
Usage
Basic Usage
With Tab Bar Icons
With Conditional Rendering
Return Value
The current color scheme preference:
'light'- Light mode is active'dark'- Dark mode is activenull- Color scheme cannot be determined (rare)
'light' during SSR before hydration completes.Source Files
- Native:
/hooks/use-color-scheme.ts - Web:
/hooks/use-color-scheme.web.ts
Related
- useThemeColor - Get theme-aware colors
- Theming - App color definitions and theme system