diff --git a/src/components/NoticeIcon/index.tsx b/src/components/NoticeIcon/index.tsx index e45990c1..72572095 100644 --- a/src/components/NoticeIcon/index.tsx +++ b/src/components/NoticeIcon/index.tsx @@ -2,7 +2,7 @@ import { useEffect, useState } from 'react'; import { Tag, message } from 'antd'; import { groupBy } from 'lodash'; import moment from 'moment'; -import { useModel } from 'umi'; +import { useModel, useRequest } from 'umi'; import { getNotices } from '@/services/ant-design-pro/api'; import NoticeIcon from './NoticeIcon'; @@ -74,10 +74,11 @@ const NoticeIconView = () => { const { initialState } = useModel('@@initialState'); const { currentUser } = initialState || {}; const [notices, setNotices] = useState([]); + const { data } = useRequest(getNotices()); useEffect(() => { - getNotices().then(({ data }) => setNotices(data || [])); - }, []); + setNotices(data || []); + }, [data]); const noticeData = getNoticeData(notices); const unreadMsg = getUnreadData(noticeData || {});