Merge pull request #1446 from AkashRajpurohit/master

feat:  customize theme and locale based on query params
This commit is contained in:
Mike Cao 2022-08-25 02:38:03 -05:00 committed by GitHub
commit 7ef4718c4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -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 };
}

View File

@ -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];
}