From 965991ae27f87a93fe6724eafc44b175bf13b224 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9D=91=BE=F0=9D=92=96=F0=9D=92=99=F0=9D=92=89?= Date: Tue, 25 Feb 2025 10:10:28 +0800 Subject: [PATCH 1/2] revert solution --- src/hooks/useNotification.tsx | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/hooks/useNotification.tsx b/src/hooks/useNotification.tsx index b250857..6b5946a 100644 --- a/src/hooks/useNotification.tsx +++ b/src/hooks/useNotification.tsx @@ -107,19 +107,11 @@ export default function useNotification( const [taskQueue, setTaskQueue] = React.useState([]); - // memorized shareConfig - const { closeIcon, closable, duration, showProgress, pauseOnHover } = shareConfig; - const memoShareConfig = React.useMemo(() => { - return { - ...shareConfig, - }; - }, [closeIcon, closable, duration, showProgress, pauseOnHover]); - // ========================= Refs ========================= const api = React.useMemo(() => { return { open: (config) => { - const mergedConfig = mergeConfig(memoShareConfig, config); + const mergedConfig = mergeConfig(shareConfig, config); if (mergedConfig.key === null || mergedConfig.key === undefined) { mergedConfig.key = `rc-notification-${uniqueKey}`; uniqueKey += 1; @@ -134,7 +126,7 @@ export default function useNotification( setTaskQueue((queue) => [...queue, { type: 'destroy' }]); }, }; - }, [memoShareConfig]); + }, []); // ======================= Container ====================== // React 18 should all in effect that we will check container in each render From 9d780167800c613049ba1fc7614a8b822efeccbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9D=91=BE=F0=9D=92=96=F0=9D=92=99=F0=9D=92=89?= Date: Tue, 25 Feb 2025 10:18:09 +0800 Subject: [PATCH 2/2] fix again --- src/hooks/useNotification.tsx | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/hooks/useNotification.tsx b/src/hooks/useNotification.tsx index 6b5946a..52f0e8d 100644 --- a/src/hooks/useNotification.tsx +++ b/src/hooks/useNotification.tsx @@ -3,6 +3,7 @@ import * as React from 'react'; import type { NotificationsProps, NotificationsRef } from '../Notifications'; import Notifications from '../Notifications'; import type { OpenConfig, Placement, StackConfig } from '../interface'; +import { useEvent } from 'rc-util'; const defaultGetContainer = () => document.body; @@ -107,26 +108,29 @@ export default function useNotification( const [taskQueue, setTaskQueue] = React.useState([]); - // ========================= Refs ========================= - const api = React.useMemo(() => { - return { - open: (config) => { - const mergedConfig = mergeConfig(shareConfig, config); - if (mergedConfig.key === null || mergedConfig.key === undefined) { - mergedConfig.key = `rc-notification-${uniqueKey}`; - uniqueKey += 1; - } + const open = useEvent((config) => { + const mergedConfig = mergeConfig(shareConfig, config); + if (mergedConfig.key === null || mergedConfig.key === undefined) { + mergedConfig.key = `rc-notification-${uniqueKey}`; + uniqueKey += 1; + } - setTaskQueue((queue) => [...queue, { type: 'open', config: mergedConfig }]); - }, + setTaskQueue((queue) => [...queue, { type: 'open', config: mergedConfig }]); + }); + + // ========================= Refs ========================= + const api = React.useMemo( + () => ({ + open: open, close: (key) => { setTaskQueue((queue) => [...queue, { type: 'close', key }]); }, destroy: () => { setTaskQueue((queue) => [...queue, { type: 'destroy' }]); }, - }; - }, []); + }), + [], + ); // ======================= Container ====================== // React 18 should all in effect that we will check container in each render