useColorScheme()

useColorScheme() provides access to the devices color scheme.

ValueDescription
colorSchemeThe current device colorScheme
setColorSchemeOverride the current colorScheme with a different scheme (accepted values are light/dark/system)
toggleColorSchemeToggle the color scheme between light and dark

You can also manually change the color scheme via NativeWindStyleSheet.setColorScheme(colorScheme)

import { useColorScheme } from "nativewind";
import { Text } from "react-native";
 
function MyComponent() {
  const { colorScheme, setColorScheme } = useColorScheme();
 
  return (
    <Text
      onPress={() => setColorScheme(colorScheme === "light" ? "dark" : "light")}
    >
      {`The color scheme is ${colorScheme}`}
    </Text>
  );
}