From f9122080daf7a3a191582b02e2713be5bf7baf2d Mon Sep 17 00:00:00 2001 From: Luke Vella Date: Thu, 28 Jul 2022 12:20:07 +0100 Subject: [PATCH] Wait for dayjs locale to load before rendering (#254) --- src/utils/dayjs.tsx | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/utils/dayjs.tsx b/src/utils/dayjs.tsx index 3898f0c8b..ff6564792 100644 --- a/src/utils/dayjs.tsx +++ b/src/utils/dayjs.tsx @@ -96,17 +96,20 @@ export const DayjsProvider: React.VoidFunctionComponent<{ return await dayjsLocales[locale ?? "en"].import(); }, [locale]); - if (dayjsLocale) { - dayjs.locale({ - ...dayjsLocale, - weekStart: weekStartsOn ? (weekStartsOn === "monday" ? 1 : 0) : undefined, - formats: { - ...dayjsLocale.formats, - LT: timeFormat === "12h" ? "h:mm A" : "H:mm", - }, - }); + if (!dayjsLocale) { + // wait for locale to load before rendering content + return null; } + dayjs.locale({ + ...dayjsLocale, + weekStart: weekStartsOn ? (weekStartsOn === "monday" ? 1 : 0) : undefined, + formats: { + ...dayjsLocale.formats, + LT: timeFormat === "12h" ? "h:mm A" : "H:mm", + }, + }); + return (