API
useLocale
ReactVanilla
The active locale, its direction, the switch function, and the current agreement context — the four things locale-aware UI reads.
const { locale, direction, setLocale, context } = useLocale()
Returns
locale
- Type:
RegisteredLocale— your registered locale union, narrowed by the typegen. Never a bare string.
direction
- Type:
'ltr' | 'rtl' - Derive
dirattributes and logical CSS from this, never from the locale tag.
setLocale
- Type:
(locale: RegisteredLocale) => void - Reactive switch that persists the user preference. Components re-render; packs load per the loading strategy.
context
- Type: the merged
LocaleScopeparams (grammatical agreement). - Read side only. Set it declaratively with
<LocaleScope>wrapping the subtree, or imperatively per key withsetParam— a hook cannot render a provider for its own children, so there is no setter here.
Examples
function LocaleSwitcher() {
const { locale, setLocale } = useLocale()
const { t } = useTranslation('common')
const supported = useConfig().locales.supported
return (
<label>
{t('language')}
<select value={locale} onChange={(e) => setLocale(e.target.value)}>
{supported.map((l) => (
<option key={l} value={l}>{l}</option>
))}
</select>
</label>
)
}
Next
- Scoped agreement params →
LocaleScope - Declaring context params → stift.config.ts
- Reading config without subscribing →
useConfig