@@ -38,7 +38,8 @@ const Notify = React.forwardRef<HTMLDivElement, NoticeProps & { times?: number }
3838 const [ percent , setPercent ] = React . useState ( 0 ) ;
3939 const [ spentTime , setSpentTime ] = React . useState ( 0 ) ;
4040 const mergedHovering = forcedHovering || hovering ;
41- const mergedShowProgress = duration && showProgress ;
41+ const mergedDuration : number = typeof duration === 'number' ? duration : 0 ;
42+ const mergedShowProgress = mergedDuration > 0 && showProgress ;
4243
4344 // ======================== Close =========================
4445 const onInternalClose = ( ) => {
@@ -53,13 +54,13 @@ const Notify = React.forwardRef<HTMLDivElement, NoticeProps & { times?: number }
5354
5455 // ======================== Effect ========================
5556 React . useEffect ( ( ) => {
56- if ( ! mergedHovering && duration ) {
57+ if ( ! mergedHovering && mergedDuration > 0 ) {
5758 const start = Date . now ( ) - spentTime ;
5859 const timeout = setTimeout (
5960 ( ) => {
6061 onInternalClose ( ) ;
6162 } ,
62- duration * 1000 - spentTime ,
63+ mergedDuration * 1000 - spentTime ,
6364 ) ;
6465
6566 return ( ) => {
@@ -70,7 +71,7 @@ const Notify = React.forwardRef<HTMLDivElement, NoticeProps & { times?: number }
7071 } ;
7172 }
7273 // eslint-disable-next-line react-hooks/exhaustive-deps
73- } , [ duration , mergedHovering , times ] ) ;
74+ } , [ mergedDuration , mergedHovering , times ] ) ;
7475
7576 React . useEffect ( ( ) => {
7677 if ( ! mergedHovering && mergedShowProgress && ( pauseOnHover || spentTime === 0 ) ) {
@@ -81,7 +82,7 @@ const Notify = React.forwardRef<HTMLDivElement, NoticeProps & { times?: number }
8182 cancelAnimationFrame ( animationFrame ) ;
8283 animationFrame = requestAnimationFrame ( ( timestamp ) => {
8384 const runtime = timestamp + spentTime - start ;
84- const progress = Math . min ( runtime / ( duration * 1000 ) , 1 ) ;
85+ const progress = Math . min ( runtime / ( mergedDuration * 1000 ) , 1 ) ;
8586 setPercent ( progress * 100 ) ;
8687 if ( progress < 1 ) {
8788 calculate ( ) ;
@@ -98,7 +99,7 @@ const Notify = React.forwardRef<HTMLDivElement, NoticeProps & { times?: number }
9899 } ;
99100 }
100101 // eslint-disable-next-line react-hooks/exhaustive-deps
101- } , [ duration , spentTime , mergedHovering , mergedShowProgress , times ] ) ;
102+ } , [ mergedDuration , spentTime , mergedHovering , mergedShowProgress , times ] ) ;
102103
103104 // ======================== Closable ========================
104105 const closableObj = React . useMemo ( ( ) => {
0 commit comments