Spaces:
Configuration error
Configuration error
Download src/components/hooks/useCountryNames.ts from SreejithSHR/umami: direct link, hf CLI and curl.
- Browser
- Download file 799 Bytes
-
https://huggingface.co/spaces/SreejithSHR/umami/resolve/main/src/components/hooks/useCountryNames.ts
- Command line
-
hf download hf://spaces/SreejithSHR/umami/src/components/hooks/useCountryNames.ts
-
curl -L -o useCountryNames.ts https://huggingface.co/spaces/SreejithSHR/umami/resolve/main/src/components/hooks/useCountryNames.ts
799 Bytes
| import { useState, useEffect } from 'react'; | |
| import { httpGet } from 'next-basics'; | |
| import enUS from '../../../public/intl/country/en-US.json'; | |
| const countryNames = { | |
| 'en-US': enUS, | |
| }; | |
| export function useCountryNames(locale: string) { | |
| const [list, setList] = useState(countryNames[locale] || enUS); | |
| async function loadData(locale: string) { | |
| const { data } = await httpGet(`${process.env.basePath || ''}/intl/country/${locale}.json`); | |
| if (data) { | |
| countryNames[locale] = data; | |
| setList(countryNames[locale]); | |
| } else { | |
| setList(enUS); | |
| } | |
| } | |
| useEffect(() => { | |
| if (!countryNames[locale]) { | |
| loadData(locale); | |
| } else { | |
| setList(countryNames[locale]); | |
| } | |
| }, [locale]); | |
| return { countryNames: list }; | |
| } | |
| export default useCountryNames; | |