From 812eb3d70fd0f565665d04fe17d7e18ba8318156 Mon Sep 17 00:00:00 2001 From: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Mon, 28 Nov 2022 10:42:21 -0800 Subject: [PATCH] Fix datetime react render error --- src/components/widgets/datetime/datetime.jsx | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/components/widgets/datetime/datetime.jsx b/src/components/widgets/datetime/datetime.jsx index dceaf06a3..7bfb42bce 100644 --- a/src/components/widgets/datetime/datetime.jsx +++ b/src/components/widgets/datetime/datetime.jsx @@ -15,22 +15,21 @@ const textSizes = { export default function DateTime({ options }) { const { text_size: textSize, format } = options; const { i18n } = useTranslation(); - const [date, setDate] = useState(new Date()); - + const dateFormat = new Intl.DateTimeFormat(i18n.language, { ...format }); + const [date, setDate] = useState(""); + useEffect(() => { const interval = setInterval(() => { - setDate(new Date()); + setDate(dateFormat.format(new Date())); }, 1000); return () => clearInterval(interval); - }, [setDate]); - - const dateFormat = new Intl.DateTimeFormat(i18n.language, { ...format }); + }, [date, setDate]); return (
- {dateFormat.format(date)} + {date}