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

queryNotification currUser传参

visuddhinanda 2 лет назад
Родитель
Сommit
dcc3ed35fd
1 измененных файлов с 6 добавлено и 5 удалено
  1. 6 5
      dashboard/src/components/notification/NotificationIcon.tsx

+ 6 - 5
dashboard/src/components/notification/NotificationIcon.tsx

@@ -6,12 +6,13 @@ import { INotificationListResponse } from "../api/notification";
 import NotificationList from "./NotificationList";
 import { useAppSelector } from "../../hooks";
 import { currentUser } from "../../reducers/current-user";
+import { IUser } from "../auth/User";
 
 const NotificationIconWidget = () => {
   const [count, setCount] = useState<number>();
-  const user = useAppSelector(currentUser);
+  const currUser = useAppSelector(currentUser);
 
-  const queryNotification = () => {
+  const queryNotification = (user?: IUser) => {
     if (!user) {
       console.debug("未登录 不查询 notification");
       return;
@@ -67,15 +68,15 @@ const NotificationIconWidget = () => {
     });
   };
   useEffect(() => {
-    let timer = setInterval(() => queryNotification(), 1000 * 60);
+    let timer = setInterval(queryNotification, 1000 * 60, currUser);
     return () => {
       clearInterval(timer);
     };
-  }, []);
+  }, [currUser]);
 
   return (
     <>
-      {user ? (
+      {currUser ? (
         <Popover
           placement="bottomLeft"
           arrowPointAtCenter