@@ -3,6 +3,7 @@ import * as React from 'react';
3
3
import type { NotificationsProps , NotificationsRef } from '../Notifications' ;
4
4
import Notifications from '../Notifications' ;
5
5
import type { OpenConfig , Placement , StackConfig } from '../interface' ;
6
+ import { useEvent } from 'rc-util' ;
6
7
7
8
const defaultGetContainer = ( ) => document . body ;
8
9
@@ -107,26 +108,29 @@ export default function useNotification(
107
108
108
109
const [ taskQueue , setTaskQueue ] = React . useState < Task [ ] > ( [ ] ) ;
109
110
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
+ }
119
117
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 ,
122
125
close : ( key ) => {
123
126
setTaskQueue ( ( queue ) => [ ...queue , { type : 'close' , key } ] ) ;
124
127
} ,
125
128
destroy : ( ) => {
126
129
setTaskQueue ( ( queue ) => [ ...queue , { type : 'destroy' } ] ) ;
127
130
} ,
128
- } ;
129
- } , [ ] ) ;
131
+ } ) ,
132
+ [ ] ,
133
+ ) ;
130
134
131
135
// ======================= Container ======================
132
136
// React 18 should all in effect that we will check container in each render
0 commit comments