Merge pull request #570 from benphelps/fix-datetime-render-error

Fix datetime react render error
pull/575/head
Jason Fischer 2 years ago committed by GitHub
commit 8a1c0a5d06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -15,22 +15,21 @@ const textSizes = {
export default function DateTime({ options }) { export default function DateTime({ options }) {
const { text_size: textSize, format } = options; const { text_size: textSize, format } = options;
const { i18n } = useTranslation(); const { i18n } = useTranslation();
const [date, setDate] = useState(new Date()); const dateFormat = new Intl.DateTimeFormat(i18n.language, { ...format });
const [date, setDate] = useState("");
useEffect(() => { useEffect(() => {
const interval = setInterval(() => { const interval = setInterval(() => {
setDate(new Date()); setDate(dateFormat.format(new Date()));
}, 1000); }, 1000);
return () => clearInterval(interval); return () => clearInterval(interval);
}, [setDate]); }, [date, setDate]);
const dateFormat = new Intl.DateTimeFormat(i18n.language, { ...format });
return ( return (
<div className="flex flex-col justify-center first:ml-0 ml-4"> <div className="flex flex-col justify-center first:ml-0 ml-4">
<div className="flex flex-row items-center grow justify-end"> <div className="flex flex-row items-center grow justify-end">
<span className={`text-theme-800 dark:text-theme-200 ${textSizes[textSize || "lg"]}`}> <span className={`text-theme-800 dark:text-theme-200 ${textSizes[textSize || "lg"]}`}>
{dateFormat.format(date)} {date}
</span> </span>
</div> </div>
</div> </div>

Loading…
Cancel
Save