@@ -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,34 +108,29 @@ export default function useNotification(
107
108
108
109
const [ taskQueue , setTaskQueue ] = React . useState < Task [ ] > ( [ ] ) ;
109
110
110
- // memorized shareConfig
111
- const { closeIcon, closable, duration, showProgress, pauseOnHover } = shareConfig ;
112
- const memoShareConfig = React . useMemo < typeof shareConfig > ( ( ) => {
113
- return {
114
- ...shareConfig ,
115
- } ;
116
- } , [ closeIcon , closable , duration , showProgress , pauseOnHover ] ) ;
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
+ }
117
117
118
- // ========================= Refs =========================
119
- const api = React . useMemo < NotificationAPI > ( ( ) => {
120
- return {
121
- open : ( config ) => {
122
- const mergedConfig = mergeConfig ( memoShareConfig , config ) ;
123
- if ( mergedConfig . key === null || mergedConfig . key === undefined ) {
124
- mergedConfig . key = `rc-notification-${ uniqueKey } ` ;
125
- uniqueKey += 1 ;
126
- }
118
+ setTaskQueue ( ( queue ) => [ ...queue , { type : 'open' , config : mergedConfig } ] ) ;
119
+ } ) ;
127
120
128
- setTaskQueue ( ( queue ) => [ ...queue , { type : 'open' , config : mergedConfig } ] ) ;
129
- } ,
121
+ // ========================= Refs =========================
122
+ const api = React . useMemo < NotificationAPI > (
123
+ ( ) => ( {
124
+ open : open ,
130
125
close : ( key ) => {
131
126
setTaskQueue ( ( queue ) => [ ...queue , { type : 'close' , key } ] ) ;
132
127
} ,
133
128
destroy : ( ) => {
134
129
setTaskQueue ( ( queue ) => [ ...queue , { type : 'destroy' } ] ) ;
135
130
} ,
136
- } ;
137
- } , [ memoShareConfig ] ) ;
131
+ } ) ,
132
+ [ ] ,
133
+ ) ;
138
134
139
135
// ======================= Container ======================
140
136
// React 18 should all in effect that we will check container in each render
0 commit comments