diff --git a/hooks/useLocale.js b/hooks/useLocale.js index fdce6d91..339ff4ba 100644 --- a/hooks/useLocale.js +++ b/hooks/useLocale.js @@ -48,5 +48,14 @@ export default function useLocale() { } }, [locale]); + useEffect(() => { + const url = new URL(window.location.href); + const locale = url.searchParams.get('locale'); + + if (locale) { + saveLocale(locale); + } + }, []); + return { locale, saveLocale, messages, dir, dateLocale }; } diff --git a/hooks/useTheme.js b/hooks/useTheme.js index cc02631e..47ac31dd 100644 --- a/hooks/useTheme.js +++ b/hooks/useTheme.js @@ -23,5 +23,14 @@ export default function useTheme() { document.body.setAttribute('data-theme', theme); }, [theme]); + useEffect(() => { + const url = new URL(window.location.href); + const theme = url.searchParams.get('theme'); + + if (['light', 'dark'].includes(theme)) { + saveTheme(theme); + } + }, []); + return [theme, saveTheme]; }