AIUI 上下文提供器
AIUI Provider 是一个 React Context 提供器,为整个应用提供全局的国际化、主题和配置上下文。它包含本地化设置、文案配置、功能开关等。
使用方式
import { AiuiProvider } from '@anker-in/headless-ui/biz'
function App() {
return (
<AiuiProvider
locale="us"
copyWriting={{ welcome: "Welcome" }}
trackingData={{ page: "home" }}
isLogin={true}
currencyCode="USD"
>
<YourAppContent />
</AiuiProvider>
)
}Context 消费
import { useAiuiContext } from '@anker-in/headless-ui/biz'
function MyComponent() {
const { locale, copyWriting, isLogin } = useAiuiContext()
return (
<div>
<p>当前语言: {locale}</p>
<p>欢迎文案: {copyWriting.welcome}</p>
<p>登录状态: {isLogin ? '已登录' : '未登录'}</p>
</div>
)
}Props 参数
| 参数名 | 类型 | 必需 | 默认值 | 描述 |
|---|---|---|---|---|
trackingData | Record<string, any> | ❌ | {} | 页面跟踪数据对象,用于埋点统计 |
locale | string | ❌ | undefined | 地区语言设置,如 ‘us’, ‘cn’ 等 |
copyWriting | Record<string, string> | ❌ | {} | 文案配置对象,键值对形式的本地化文案 |
pathname | string | ❌ | undefined | 当前页面路径 |
storeDomain | string | ❌ | undefined | 商店域名 |
isLogin | boolean | ❌ | undefined | 用户登录状态 |
currencyCode | string | ❌ | undefined | 货币代码,如 ‘USD’, ‘CNY’ 等 |
Last updated on