Fix datetime react render error

pull/570/head
Michael Shamoon 2 years ago
parent 9de82559ca
commit 812eb3d70f

@ -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 (
<div className="flex flex-col justify-center first:ml-0 ml-4">
<div className="flex flex-row items-center grow justify-end">
<span className={`text-theme-800 dark:text-theme-200 ${textSizes[textSize || "lg"]}`}>
{dateFormat.format(date)}
{date}
</span>
</div>
</div>

Loading…
Cancel
Save