Skip to content

KanjouProvider

The <KanjouProvider> component wraps your React application and provides the i18n context (messages, locale, options, etc.) to all nested components and hooks.

Import

ts
import { KanjouProvider } from '@kanjou/react'

Usage

tsx
import { KanjouProvider } from '@kanjou/react'
import { App } from './App'
import en from './locales/en.json'

export function Root() {
  return (
    <KanjouProvider locale="en" messages={en}>
      <App />
    </KanjouProvider>
  )
}

Props

PropTypeDescription
childrenReactNodeThe React children to wrap.
localestringThe current locale (e.g. 'en', 'fr-CA').
messagesRecord<string, Message>The dictionary of MessageFormat 2 messages.
functionsFunctionsOptional custom functions to be used inside your messages.
componentsRichComponentsOptional React components to use for rich text formatting globally.
optionsOmit<MessageFormatOptions, 'functions'>Optional configuration for MessageFormat.

TIP

For full End-to-End type safety, make sure you configure your TypeScript declarations for @kanjou/react to pick up your available locales and messages.

Released under the ISC License.