Browse Source
fix: fix NoticeIcon state update on an unmounted component (#8726)
pull/8731/head
陈帅
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
4 additions and
3 deletions
-
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<API.NoticeIconItem[]>([]); |
|
|
|
const { data } = useRequest(getNotices()); |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
getNotices().then(({ data }) => setNotices(data || [])); |
|
|
|
}, []); |
|
|
|
setNotices(data || []); |
|
|
|
}, [data]); |
|
|
|
|
|
|
|
const noticeData = getNoticeData(notices); |
|
|
|
const unreadMsg = getUnreadData(noticeData || {}); |
|
|
|
|