Skip to content

Commit 9d78016

Browse files
committed
fix again
1 parent 965991a commit 9d78016

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/hooks/useNotification.tsx

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as React from 'react';
33
import type { NotificationsProps, NotificationsRef } from '../Notifications';
44
import Notifications from '../Notifications';
55
import type { OpenConfig, Placement, StackConfig } from '../interface';
6+
import { useEvent } from 'rc-util';
67

78
const defaultGetContainer = () => document.body;
89

@@ -107,26 +108,29 @@ export default function useNotification(
107108

108109
const [taskQueue, setTaskQueue] = React.useState<Task[]>([]);
109110

110-
// ========================= Refs =========================
111-
const api = React.useMemo<NotificationAPI>(() => {
112-
return {
113-
open: (config) => {
114-
const mergedConfig = mergeConfig(shareConfig, config);
115-
if (mergedConfig.key === null || mergedConfig.key === undefined) {
116-
mergedConfig.key = `rc-notification-${uniqueKey}`;
117-
uniqueKey += 1;
118-
}
111+
const open = useEvent<NotificationAPI['open']>((config) => {
112+
const mergedConfig = mergeConfig(shareConfig, config);
113+
if (mergedConfig.key === null || mergedConfig.key === undefined) {
114+
mergedConfig.key = `rc-notification-${uniqueKey}`;
115+
uniqueKey += 1;
116+
}
119117

120-
setTaskQueue((queue) => [...queue, { type: 'open', config: mergedConfig }]);
121-
},
118+
setTaskQueue((queue) => [...queue, { type: 'open', config: mergedConfig }]);
119+
});
120+
121+
// ========================= Refs =========================
122+
const api = React.useMemo<NotificationAPI>(
123+
() => ({
124+
open: open,
122125
close: (key) => {
123126
setTaskQueue((queue) => [...queue, { type: 'close', key }]);
124127
},
125128
destroy: () => {
126129
setTaskQueue((queue) => [...queue, { type: 'destroy' }]);
127130
},
128-
};
129-
}, []);
131+
}),
132+
[],
133+
);
130134

131135
// ======================= Container ======================
132136
// React 18 should all in effect that we will check container in each render

0 commit comments

Comments
 (0)