From ec7bc92497eb4b472df963833c3d52bf086a46ef Mon Sep 17 00:00:00 2001 From: akashrajpurohit_postman Date: Sun, 21 Aug 2022 17:00:40 +0530 Subject: [PATCH] feat: :sparkles: customize theme and locale based on query params --- hooks/useLocale.js | 9 +++++++++ hooks/useTheme.js | 9 +++++++++ 2 files changed, 18 insertions(+) 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]; }