Skip to main content
196

Search Lumen

Find components, APIs, guides, and recipes.

GitHub
Web docs
Selection and preferences

useLanguageToggle

Coordinates controlled or uncontrolled locale cycling, persistence, and document language synchronization for React applications.

Live component preview · Astro

Explore LanguageToggle

Try the component this hook connects to. The preview uses the Astro adapter; the React example below uses useLanguageToggle.

React usage

Import from @santi020k/lumen-react and spread the controller props onto the matching components.

tsxuseLanguageToggle example
import { LanguageToggle } from '@santi020k/lumen-react'

export function LocaleControl() {
  return (
    <LanguageToggle
      defaultValue="en"
      storageKey="site-language"
      locales={[
        { label: 'English', value: 'en' },
        { label: 'Español', value: 'es' }
      ]}
    />
  )
}
import { LanguageToggle } from '@santi020k/lumen-react'

export function LocaleControl() {
  return (
    <LanguageToggle
      defaultValue="en"
      storageKey="site-language"
      locales={[
        { label: 'English', value: 'en' },
        { label: 'Español', value: 'es' }
      ]}
    />
  )
}

Load @santi020k/lumen-react/styles.css once in your application. With React Server Components, put 'use client' at the top of the module that calls the hook. Follow the React setup guide for the framework boundary.

Options

PropertyTypeDefaultDescription
defaultValuestringfirst localeInitial uncontrolled locale value.
valuestring-Controlled locale value.
localesLumenLocaleOption[]English and SpanishOrdered locale values and visible labels.
storageKeystring-Persists and restores the uncontrolled locale when storage is available.
onValueChange(value: string) => void-Receives the next requested or applied locale.

Controller return values

PropertyTypeDescription
valuestringCurrent locale value.
currentLocaleLumenLocaleOptionCurrent locale value and label.
nextLocaleLumenLocaleOptionNext locale value and label.
selectNext() => voidRequests or applies the next locale.
Web docsFull catalog