React reference
Ways
Root props
Common root props:
| Prop | Type | Notes |
|---|---|---|
apiKey | string | Required. |
locale | string | Current target locale. |
baseLocale | string | Source locale. |
persistLocaleCookie | boolean | Default locale-cookie policy for the root runtime. |
context | string | object | Optional root context. |
cacheTtl | number | Cache TTL for translation requests. |
messageFormatter | 'waysParser' | 'none' | fn | Parser or formatter override. |
suspenseTimeoutMs | number | Max time render blocking is allowed before fallback rendering continues. |
fetcher | typeof fetch | Custom fetch implementation. |
acceptedLocales | string[] | Optional explicit locale list. |
Scoped props
Nested scopes accept:
| Prop | Type | Notes |
|---|---|---|
context | string | object | Required. |
locale | string | Available, but use a nested root for an isolated locale session. |
baseLocale | string | Optional source-locale override for the subtree. |
components | Record<string, component> | Components used inside translatable content. |
T
T is the JSX-first translation primitive.
| Prop | Type | Notes |
|---|---|---|
children | ReactNode | Required. |
vars | Record<string, unknown> | Interpolation input. |
context | string | object | Optional leaf context override. |
components | Record<string, component> | Component mapping for rich content. |
fixed | boolean | Skip translation for fixed branding-like content. |
useT()
useT() returns a translation function for strings, attributes, and logic.
const t = useT();
const label = t('Save changes');Runtime hooks
useTranslatedMemo()
A memoized value that recomputes when translations change.
useTranslationLoading()
Returns true while the current context is still loading.
useCurrentLocale()
Reads the selected locale for the current root runtime.
useTargetLocale()
Reads the active target locale for the current scope.
useBaseLocale()
Reads the source locale for the current root runtime.
useSetCurrentLocale()
Returns the setter for the root runtime locale.
useAcceptedLocales()
Reads the resolved accepted locale list from the root runtime.
LanguageSwitcher
Common props:
| Prop | Type | Notes |
|---|---|---|
currentLocale | string | Controlled locale. |
onLocaleChange | (locale) => void | Change handler. |
direction | 'up' | 'down' | Menu direction. |
styles / classNames | object | Styling overrides. |
unstyled | boolean | Disable built-in styles. |
Utility exports
@18ways/react also re-exports:
fetchAcceptedLocalesfetchConfigresolveOrigin