@@ -3,17 +3,18 @@ import { useEffect, useRef } from 'react';
33/**
44 * Hook to handle automatic toast dismissal based on duration
55 *
6- * @param duration - Duration in milliseconds before the toast automatically disappears
6+ * @param duration - Duration in milliseconds before the toast automatically disappears, or 'persistent' to prevent auto-hide
77 * @param id - The unique ID of the toast
88 * @param hide - Function to hide the toast
99 *
1010 * @example
1111 * ```tsx
1212 * useToastDuration(4000, toastId, hide);
13+ * useToastDuration('persistent', toastId, hide);
1314 * ```
1415 */
1516export function useToastDuration (
16- duration : number | null | undefined ,
17+ duration : number | 'persistent' | undefined ,
1718 id : string | undefined ,
1819 hide : ( ( ids ?: string | string [ ] ) => void ) | undefined
1920) : void {
@@ -26,10 +27,16 @@ export function useToastDuration(
2627 timeoutRef . current = null ;
2728 }
2829
29- // Only set timeout if duration is valid and id/hide are available
30+ // Handle immediate dismissal
31+ if ( duration === 0 && id && hide ) {
32+ hide ( id ) ;
33+ return ;
34+ }
35+
36+ // Only set timeout if duration is a valid positive number and id/hide are available
37+ // Skip timeout if duration is 'persistent', undefined, or invalid (treats as persistent)
3038 if (
31- duration !== null &&
32- duration !== undefined &&
39+ typeof duration === 'number' &&
3340 ! isNaN ( duration ) &&
3441 duration > 0 &&
3542 duration !== Infinity &&
0 commit comments