🐛 Fix dayjs locale should default to router locale

This commit is contained in:
Luke Vella 2023-10-23 09:51:11 +01:00
parent 7c54268b58
commit c6b17aa22b

View file

@ -11,6 +11,7 @@ import relativeTime from "dayjs/plugin/relativeTime";
import timezone from "dayjs/plugin/timezone"; import timezone from "dayjs/plugin/timezone";
import updateLocale from "dayjs/plugin/updateLocale"; import updateLocale from "dayjs/plugin/updateLocale";
import utc from "dayjs/plugin/utc"; import utc from "dayjs/plugin/utc";
import { useRouter } from "next/router";
import * as React from "react"; import * as React from "react";
import { useAsync } from "react-use"; import { useAsync } from "react-use";
@ -188,7 +189,8 @@ export const DayjsProvider: React.FunctionComponent<{
}; };
}; };
}> = ({ config, children }) => { }> = ({ config, children }) => {
const l = config?.locale ?? "en"; const router = useRouter();
const l = config?.locale ?? router.locale ?? "en";
const state = useAsync(async () => { const state = useAsync(async () => {
return await dayjsLocales[l].import(); return await dayjsLocales[l].import();
}, [l]); }, [l]);
@ -249,7 +251,6 @@ export const ConnectedDayjsProvider = ({
children, children,
}: React.PropsWithChildren) => { }: React.PropsWithChildren) => {
const { preferences } = usePreferences(); const { preferences } = usePreferences();
return ( return (
<DayjsProvider <DayjsProvider
config={{ config={{