Skip to content

Commit

Permalink
Fix code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiodxa committed Aug 5, 2024
1 parent cc1818c commit 1073001
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import { useTranslation } from "react-i18next";
* let formattedDate = date.toLocaleDateString(locale);
*/
export function useLocale(localeKey = "locale"): string {
let matches = useMatches();
// biome-ignore lint/style/noNonNullAssertion: There's always a root match
let rootMatch = matches.at(0)!;
let { [localeKey]: locale } =
(rootMatch.data as Record<string, string>) ?? {};
if (!locale) throw new Error("Missing locale returned by the root loader.");
if (typeof locale === "string") return locale;
throw new Error("Invalid locale returned by the root loader.");
let matches = useMatches();
// biome-ignore lint/style/noNonNullAssertion: There's always a root match
let rootMatch = matches.at(0)!;
let { [localeKey]: locale } =
(rootMatch.data as Record<string, string>) ?? {};
if (!locale) throw new Error("Missing locale returned by the root loader.");
if (typeof locale === "string") return locale;
throw new Error("Invalid locale returned by the root loader.");
}

/**
Expand All @@ -28,8 +28,8 @@ export function useLocale(localeKey = "locale"): string {
* This will ensure translations are loaded automatically.
*/
export function useChangeLanguage(locale: string) {
let { i18n } = useTranslation();
React.useEffect(() => {
i18n.changeLanguage(locale);
}, [locale, i18n]);
let { i18n } = useTranslation();
React.useEffect(() => {
i18n.changeLanguage(locale);
}, [locale, i18n]);
}

0 comments on commit 1073001

Please sign in to comment.