Browse Source

fix: fix NoticeIcon state update on an unmounted component (#8726)

pull/8731/head
陈帅 5 years ago
committed by GitHub
parent
commit
64c4f05cb4
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      src/components/NoticeIcon/index.tsx

7
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 || {});

Loading…
Cancel
Save