@hua-labs/i18n-core-zustand
v2.2.1
Published
Zustand adapter for @hua-labs/i18n-core - Type-safe state management integration
Maintainers
Readme
@hua-labs/i18n-core-zustand
Type-safe adapter for integrating Zustand state management with @hua-labs/i18n-core. Provides seamless language state synchronization with SSR hydration support and circular reference prevention.
Features
- Type-safe — Full TypeScript support
- Auto-sync — Zustand store changes automatically sync to i18n
- SSR compatible — Language syncs after hydration to prevent mismatches
- Circular reference prevention — Safe unidirectional data flow
- React Native — Works in Expo and bare RN projects
- Minimal — Only Zustand as peer dependency
Installation
pnpm add @hua-labs/i18n-core-zustandPeer dependencies: react >=19.0.0, zustand ^4.0.0 || ^5.0.0
Quick Start
import { createZustandI18n } from '@hua-labs/i18n-core-zustand';
import { useTranslation } from '@hua-labs/i18n-core';
import { useAppStore } from './store';
const I18nProvider = createZustandI18n(useAppStore, {
fallbackLanguage: 'en',
namespaces: ['common', 'navigation'],
translationLoader: 'api',
translationApiPath: '/api/translations',
defaultLanguage: 'ko',
});
export default function Layout({ children }) {
return <I18nProvider>{children}</I18nProvider>;
}
function MyComponent() {
const { t } = useTranslation();
return <h1>{t('common:welcome')}</h1>;
}
API
| Export | Type | Description |
|--------|------|-------------|
| createZustandI18n | function | Create an i18n Provider integrated with Zustand store |
| useZustandI18n | hook | Hook returning { language, setLanguage } from Zustand |
Documentation
Related Packages
License
MIT — HUA Labs
