From 9675616b450e0b163e051fa00799ccdb8626002f Mon Sep 17 00:00:00 2001 From: Vlad Fernandes Date: Thu, 14 Sep 2023 10:18:15 -0400 Subject: [PATCH] fix for next.js localstorage is not available on the server and will throw an error, this is safe check to bypass the error --- locales/locale.js | 2 +- src/Scheduler.jsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/locales/locale.js b/locales/locale.js index f6f0944..43cf2a5 100644 --- a/locales/locale.js +++ b/locales/locale.js @@ -28,7 +28,7 @@ i18n // for all options read: https://www.i18next.com/overview/configuration-options .init({ resources, - lng: localStorage.getItem('i18nextLng'), + lng: localStorage ? localStorage.getItem('i18nextLng'): 'en', ns: ["common"], defaultNS: "common", fallbackNS: "common", diff --git a/src/Scheduler.jsx b/src/Scheduler.jsx index 5f7fe49..d9f60c3 100644 --- a/src/Scheduler.jsx +++ b/src/Scheduler.jsx @@ -474,7 +474,7 @@ function Scheduler(props) { ]) useEffect(() => { - if (locale !== i18n.language) { //localStorage.getItem('i18nextLng') + if (locale !== i18n.language && localStorage) { //localStorage.getItem('i18nextLng') localStorage.setItem('i18nextLng', locale.toLowerCase()) i18n.changeLanguage(locale.toLowerCase()) updateWeekDays()