useConfig.ts 922 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { useContext, use } from "react";
  2. import { ConfigContext } from "@/providers/ConfigProvider";
  3. export function useStore(){
  4. const context = useContext(ConfigContext);
  5. if(!context){
  6. throw new Error(
  7. "useConfig must be used inside ConfigProvider"
  8. );
  9. }
  10. const {store} = context.config;
  11. return {
  12. store,
  13. setCurrentCurrency: context.setCurrentCurrency
  14. };
  15. }
  16. export function useCountries() {
  17. const context = useContext(ConfigContext);
  18. if (!context) {
  19. throw new Error(
  20. "useCountries must be used within ConfigProvider",
  21. );
  22. }
  23. return use(context.config.countriesPromise);
  24. }
  25. export function useCurrencyList() {
  26. const context = useContext(ConfigContext);
  27. if (!context) {
  28. throw new Error(
  29. "useCurrencyList must be used within ConfigProvider",
  30. );
  31. }
  32. return use(context.config.currenciesPromise);
  33. }