@@ -67,19 +67,8 @@ const InternalToast = React.forwardRef<HTMLDivElement, InternalToastProps>(funct
67
67
} ,
68
68
ref ,
69
69
) {
70
- const [ timeoutRunning , setTimeoutRunning ] = React . useState ( Boolean ( autoDismissDelay ) )
71
70
const timeoutRef = React . useRef < number | undefined > ( )
72
71
73
- const startTimeout = React . useCallback ( function startTimeout ( ) {
74
- setTimeoutRunning ( true )
75
- } , [ ] )
76
-
77
- const stopTimeout = React . useCallback ( function stopTimeout ( ) {
78
- setTimeoutRunning ( false )
79
- clearTimeout ( timeoutRef . current )
80
- timeoutRef . current = undefined
81
- } , [ ] )
82
-
83
72
const removeToast = React . useCallback (
84
73
function removeToast ( ) {
85
74
onRemoveToast ( toastId )
@@ -88,13 +77,27 @@ const InternalToast = React.forwardRef<HTMLDivElement, InternalToastProps>(funct
88
77
[ onDismiss , onRemoveToast , toastId ] ,
89
78
)
90
79
80
+ const startTimeout = React . useCallback (
81
+ function startTimeout ( ) {
82
+ if ( ! autoDismissDelay ) return
83
+ timeoutRef . current = window . setTimeout ( removeToast , autoDismissDelay * 1000 )
84
+ } ,
85
+ [ autoDismissDelay , removeToast ] ,
86
+ )
87
+
88
+ const stopTimeout = React . useCallback ( function stopTimeout ( ) {
89
+ clearTimeout ( timeoutRef . current )
90
+ timeoutRef . current = undefined
91
+ } , [ ] )
92
+
91
93
React . useEffect (
92
94
function setupAutoDismiss ( ) {
93
- if ( ! timeoutRunning || ! autoDismissDelay ) return
94
- timeoutRef . current = window . setTimeout ( removeToast , autoDismissDelay * 1000 )
95
+ stopTimeout ( )
96
+ startTimeout ( )
97
+
95
98
return stopTimeout
96
99
} ,
97
- [ autoDismissDelay , removeToast , stopTimeout , timeoutRunning ] ,
100
+ [ startTimeout , stopTimeout ] ,
98
101
)
99
102
100
103
/**
0 commit comments