From 64c4f05cb4cbbfecb52560d29c39c448091cd5a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=B8=85?= Date: Tue, 13 Jul 2021 14:09:26 +0800 Subject: [PATCH] fix: fix NoticeIcon state update on an unmounted component (#8726) --- src/components/NoticeIcon/index.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 || {});