Skip to content

Commit

Permalink
fix: import of locale from dayjs static
Browse files Browse the repository at this point in the history
  • Loading branch information
syam babu committed Oct 14, 2024
1 parent ccda272 commit 10e91a3
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,24 @@ import { dynamicCssColorInjector, dynamicFontInjector } from './utils/dynamicSty
import { useEffect, useState } from 'react';
import dayjs from 'dayjs';
import Loader from './components/loader/Loader';

const locales = {
en: () => import('dayjs/locale/en'),
fr: () => import('dayjs/locale/fr'),
};
require('dayjs/locale/en');
require('dayjs/locale/fr');

function App(props) {
const { color, font, ...widgetProps } = props;
const locale = widgetProps.locale;
const [loading, setLoading] = useState(true);

useEffect(() => {
if (locales[locale]) {
locales[locale]()
.then(() => {
dayjs.locale(locale);
setLoading(false);
})
.catch((error) => {
console.error(`Failed to load locale: ${locale}`, error);
dayjs.locale('en'); // Fallback to 'en'
setLoading(false);
});
} else {
try {
if (locale) {
dayjs.locale(locale);
} else {
dayjs.locale('en');
}
setLoading(false);
} catch (error) {
console.error(`Failed to set locale: ${locale}`, error);
dayjs.locale('en');
setLoading(false);
}
Expand Down

0 comments on commit 10e91a3

Please sign in to comment.