Skip to content

useGrundtoneTheme

Access the current theme from any component within a GrundtoneThemeProvider.

Usage

tsx
import { useGrundtoneTheme } from '@grundtone/react-native';

function MyScreen() {
  const { theme, isDark, toggleMode } = useGrundtoneTheme();

  return (
    <View style={{ backgroundColor: theme.colors.background }}>
      <Text style={{ color: theme.colors.text }}>Hello</Text>
    </View>
  );
}

Return value

PropertyTypeDescription
themeThemeCurrent resolved theme object
modeThemeModeCurrent mode: 'light', 'dark', or 'auto'
isDarkbooleanWhether dark mode is active
isLightbooleanWhether light mode is active
setMode(mode: ThemeMode) => voidSet the theme mode
toggleMode() => voidToggle between light and dark

Requirements

Must be used inside a component tree wrapped with GrundtoneThemeProvider. Throws an error if no provider is found.