mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-09-07 19:55:46 -05:00
20 lines
658 B
TypeScript
20 lines
658 B
TypeScript
import * as React from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import type { LanguageCode } from "~/modules/i18n/config";
|
|
import { loadDateFnsLocale } from "~/utils/dates";
|
|
|
|
/**
|
|
* Calls `i18n.changeLanguage` when the root loader's locale changes, loading the date-fns locale first so
|
|
* the re-render already has it. Vendored from remix-i18next (removed in v8).
|
|
*/
|
|
export function useChangeLanguage(locale: string) {
|
|
const { i18n } = useTranslation();
|
|
React.useEffect(() => {
|
|
if (i18n.language !== locale) {
|
|
void loadDateFnsLocale(locale as LanguageCode).then(() =>
|
|
i18n.changeLanguage(locale),
|
|
);
|
|
}
|
|
}, [locale, i18n]);
|
|
}
|