返回 CodeWhale
use-country-label.ts
根目录 / web / components / use-country-label.ts
1 "use client";
2
3 import { useSyncExternalStore } from "react";
4 import { countryLabel } from "@/lib/content/merch-storefront";
5
6 const subscribe = () => () => {};
7
8 export function useCountryLabel(locale: string): (code: string, fallback: string) => string {
9 const mounted = useSyncExternalStore(subscribe, () => true, () => false);
10 return (code, fallback) => (mounted && !locale.startsWith("en") ? countryLabel(code, fallback, locale) : fallback);
11 }
12
12 lines TYPESCRIPT