ConfigProvider.tsx 886 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. "use client";
  2. import {
  3. createContext,
  4. } from "react";
  5. import {CurrencyItem} from "@/types/currency/type";
  6. import { Country } from "@/types/checkout/type";
  7. export interface StoreConfig {
  8. storeName: string;
  9. defaultCurrency: string;
  10. defaultLocale: string;
  11. defaultChannel: string;
  12. currentCurrency: string; // 货币码 e.g. USD GBP
  13. currentLocale: string;
  14. currentChannel: string;
  15. }
  16. export interface AppConfig {
  17. currencies: CurrencyItem[];
  18. countries: Country[];
  19. store: StoreConfig;
  20. }
  21. export const ConfigContext = createContext<AppConfig|null>(null);
  22. export function ConfigProvider({
  23. config,
  24. children
  25. }:{
  26. config:AppConfig;
  27. children:React.ReactNode;
  28. }){
  29. return (
  30. <ConfigContext.Provider
  31. value={config}
  32. >
  33. {children}
  34. </ConfigContext.Provider>
  35. );
  36. }