@@ -3,6 +3,7 @@ import * as React from 'react';
33import type { NotificationsProps , NotificationsRef } from '../Notifications' ;
44import Notifications from '../Notifications' ;
55import type { OpenConfig , Placement , StackConfig } from '../interface' ;
6+ import { useEvent } from 'rc-util' ;
67
78const defaultGetContainer = ( ) => document . body ;
89
@@ -107,34 +108,29 @@ export default function useNotification(
107108
108109 const [ taskQueue , setTaskQueue ] = React . useState < Task [ ] > ( [ ] ) ;
109110
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+ }
117117
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+ } ) ;
127120
128- setTaskQueue ( ( queue ) => [ ...queue , { type : 'open' , config : mergedConfig } ] ) ;
129- } ,
121+ // ========================= Refs =========================
122+ const api = React . useMemo < NotificationAPI > (
123+ ( ) => ( {
124+ open : open ,
130125 close : ( key ) => {
131126 setTaskQueue ( ( queue ) => [ ...queue , { type : 'close' , key } ] ) ;
132127 } ,
133128 destroy : ( ) => {
134129 setTaskQueue ( ( queue ) => [ ...queue , { type : 'destroy' } ] ) ;
135130 } ,
136- } ;
137- } , [ memoShareConfig ] ) ;
131+ } ) ,
132+ [ ] ,
133+ ) ;
138134
139135 // ======================= Container ======================
140136 // React 18 should all in effect that we will check container in each render
0 commit comments