Просмотр исходного кода

移动 getPassDataTime 到 useEffect

visuddhinanda 3 лет назад
Родитель
Сommit
3d5900ab29
1 измененных файлов с 15 добавлено и 2 удалено
  1. 15 2
      dashboard/src/components/general/TimeShow.tsx

+ 15 - 2
dashboard/src/components/general/TimeShow.tsx

@@ -1,6 +1,7 @@
 import { Space, Tooltip } from "antd";
 import { useIntl } from "react-intl";
 import { FieldTimeOutlined } from "@ant-design/icons";
+import { useEffect, useRef, useState } from "react";
 
 interface IWidgetTimeShow {
   showIcon?: boolean;
@@ -16,12 +17,24 @@ const Widget = ({
   title,
 }: IWidgetTimeShow) => {
   const intl = useIntl(); //i18n
-  if (typeof time === "undefined") {
+  const [passTime, setPassTime] = useState<string>();
+  console.log("time", time);
+  const updateTime = () => {
+    console.log("timer", time);
+    if (typeof time !== "undefined" && time !== "") {
+      setPassTime(getPassDataTime(time));
+    }
+  };
+
+  useEffect(() => {
+    updateTime();
+  }, [time]);
+
+  if (typeof time === "undefined" || time === "") {
     return <></>;
   }
   const icon = showIcon ? <FieldTimeOutlined /> : <></>;
 
-  const passTime: string = getPassDataTime(time);
   const tooltip: string = getFullDataTime(time);
   const color = "lime";
   function getPassDataTime(t: string): string {