From 6ca2efdfb6864145944db7d3d87cf725d37558e4 Mon Sep 17 00:00:00 2001 From: secondl1ght Date: Fri, 5 Jul 2024 16:09:38 -0600 Subject: [PATCH] refactor: move to fn dec --- src/components/LanguageToggle.tsx | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/components/LanguageToggle.tsx b/src/components/LanguageToggle.tsx index 247a37ea..fcbf1f1a 100644 --- a/src/components/LanguageToggle.tsx +++ b/src/components/LanguageToggle.tsx @@ -14,6 +14,12 @@ import { } from '@/components/ui/dropdown-menu'; import { SupportedLanguage } from '@/i18n'; +const getCookie = () => + document.cookie + .split('; ') + .find(c => c.startsWith('locale=')) + ?.split('=')[1] as SupportedLanguage | undefined; + const setCookie = (locale: SupportedLanguage) => (document.cookie = `locale=${locale}; max-age=31536000; path=/;`); @@ -24,14 +30,7 @@ export function LanguageToggle() { const { refresh } = useRouter(); const [language, setLanguage] = useState( - () => { - const localeCookie = document.cookie - .split('; ') - .find(c => c.startsWith('locale=')) - ?.split('=')[1] as SupportedLanguage | undefined; - - return localeCookie; - } + getCookie() ); return (