@hua-labs/state
v1.0.3
Published
HUA State - Unified state management for hua framework with SSR support and integrations
Downloads
1,087
Maintainers
Readme
@hua-labs/state
Zustand-based state management wrapper optimized for the hua ecosystem. Provides built-in SSR hydration handling, localStorage persistence with partialize support, and seamless i18n integration for React and Next.js applications.
Features
- Zustand-based — Lightweight, performant state management
- SSR support — Automatic hydration handling for Next.js App Router
- Persistence — Built-in localStorage with partialize support
- i18n integration — Pre-configured store for language management
- Type-safe — Full TypeScript support with strict typing
Installation
pnpm add @hua-labs/statePeer dependencies: react >=19.0.0, react-dom >=19.0.0, zustand >=5.0.0
Quick Start
import { createHuaStore } from '@hua-labs/state';
interface AppState {
theme: 'light' | 'dark';
setTheme: (theme: 'light' | 'dark') => void;
}
const useAppStore = createHuaStore<AppState>((set) => ({
theme: 'light',
setTheme: (theme) => set({ theme }),
}), {
persist: true,
persistKey: 'app-storage',
ssr: true,
});
function ThemeToggle() {
const theme = useAppStore((s) => s.theme);
const setTheme = useAppStore((s) => s.setTheme);
return <button onClick={() => setTheme(theme === 'light' ? 'dark' : 'light')}>{theme}</button>;
}
API
| Export | Type | Description |
|--------|------|-------------|
| createHuaStore | function | Create a Zustand store with SSR/persistence support |
| isStoreRehydrated | function | |
| onStoreRehydrated | function | |
| markStoreRehydrated | function | |
| createI18nStore | function | Create a pre-configured i18n language store |
| StoreCreator | type | |
| StoreConfig | type | |
| HuaStore | type | |
| BaseStoreState | type | |
| UseBoundStore | type | |
| StoreApi | type | |
| I18nStoreState | type | |
| I18nStoreConfig | type | |
| UseStoreHook | type | |
Documentation
Related Packages
License
MIT — HUA Labs
