Overview
TheuseColorScheme hook provides a way to detect and manage the current color scheme (light or dark mode) in your React Native application. While NativeWind previously provided this hook, it’s now recommended to use React Native’s built-in useColorScheme hook directly.
Import
For new projects, import from
react-native instead:Type Signature
Return Value
The current color scheme of the device. Can be
'light', 'dark', null, or undefined.Function to manually set the color scheme. Updates the appearance using React Native’s
Appearance.setColorScheme().Convenience function that toggles between light and dark mode. Switches to dark if currently light, and vice versa.
Usage
Migration Guide
If you’re using the deprecated NativeWinduseColorScheme, migrate to React Native’s version:
Implementation Details
The NativeWinduseColorScheme hook is a wrapper around React Native’s core functionality:
- Uses
useColorSchemefrom React Native to get the current color scheme - Provides
setColorSchemeviaAppearance.setColorScheme() - Implements
toggleColorSchemeby reading current scheme withAppearance.getColorScheme()and switching between light/dark