# useKivaHostTheme / useKivaHostLocale URL: /docs/web/hooks/use-kiva-host-appearance Follow the Kiva shell's colour mode and language from inside an embedded app, so a theme or language switch in the shell reaches the app it is hosting. An app embedded in the Kiva shell runs in its own iframe, so it does not inherit the shell's theme or language. Without these hooks the user switches the shell to dark mode or to Turkish and every embedded app stays light and English. Both hooks are **no-ops outside an embedded context**, so they are safe to mount unconditionally in an app that also runs standalone. ## Installation ```bash pnpm dlx @kivacore/ui-cli add @kivacore/hooks-use-kiva-host-appearance ``` ## Usage The hooks only *report* the host's value — you apply it, so the library stays independent of which theming or i18n package you use. ```tsx import { useTheme } from '@kivacore/theme-provider'; import { useTranslation } from 'react-i18next'; import { useKivaHostTheme, useKivaHostLocale } from '@/hooks/use-kiva-host-appearance'; export function useShellAppearance() { const { setTheme } = useTheme(); const { i18n } = useTranslation(); useKivaHostTheme(setTheme); useKivaHostLocale(locale => void i18n.changeLanguage(locale)); } ``` Mount it once, near the root: ```tsx function App() { useShellAppearance(); return ; } ``` ### Keeping component copy in step If you also mount a [translation catalog](/docs/web/guide/i18n), swap it in the same handler so Kiva component copy follows the shell too: ```tsx useKivaHostLocale(async (locale) => { void i18n.changeLanguage(locale); setMessages((await import(`@/locales/kiva/${locale}.json`)).default); }); ``` ## How the shell delivers it Two channels, by design: | | Carries | Why | |---|---|---| | `?theme=` / `?lang=` on the iframe URL | the value the app **boots** with | the first paint is already correct — no flash of the wrong theme | | `theme-change` / `locale-change` postMessage | every **later** switch | changing the URL instead would reload the iframe and lose the app's state | The hooks read the query params on mount and listen for the messages afterwards, so you only wire the handler once. ## API Reference ### `useKivaHostTheme(onThemeChange, options?)` | Parameter | Type | Description | |-----------|------|-------------| | `onThemeChange` | `(mode: KivaHostThemeMode) => void` | Called with the host's colour mode — on mount when the URL carries one, and on every later change | | `options` | `KivaHostAppearanceOptions` | Origin policy overrides | ### `useKivaHostLocale(onLocaleChange, options?)` | Parameter | Type | Description | |-----------|------|-------------| | `onLocaleChange` | `(locale: string) => void` | Called with the host's active language code | | `options` | `KivaHostAppearanceOptions` | Origin policy overrides | ### `isKivaHostEmbedded()` Returns `true` when the document is inside an iframe or a React Native WebView. Both hooks use it internally; it is exported so you can branch on it yourself (hiding an in-app theme switcher when the shell owns the theme, for example). ## Type Reference ### `KivaHostThemeMode` ```ts type KivaHostThemeMode = 'light' | 'dark' | 'system'; ``` ### `KivaHostAppearanceOptions` | Field | Type | Default | Description | |-------|------|---------|-------------| | `allowedOrigins` | `string[]` | `[]` | Extra origins to trust, beyond the pattern — a local shell or a staging host | | `allowedOriginPattern` | `RegExp` | `/^https:\/\/[^/]+\.(?:kiva\|docyrus)\.app$/` | Host origins to accept messages from |