@@ -437,33 +437,6 @@ function getDocumentDirection(): ToasterProps['dir'] {
437
437
return dirAttribute as ToasterProps [ 'dir' ] ;
438
438
}
439
439
440
- function useSonner ( ) {
441
- const [ activeToasts , setActiveToasts ] = React . useState < ToastT [ ] > ( [ ] ) ;
442
-
443
- React . useEffect ( ( ) => {
444
- return ToastState . subscribe ( ( toast ) => {
445
- setActiveToasts ( ( currentToasts ) => {
446
- if ( 'dismiss' in toast && toast . dismiss ) {
447
- return currentToasts . filter ( ( t ) => t . id !== toast . id ) ;
448
- }
449
-
450
- const existingToastIndex = currentToasts . findIndex ( ( t ) => t . id === toast . id ) ;
451
- if ( existingToastIndex !== - 1 ) {
452
- const updatedToasts = [ ...currentToasts ] ;
453
- updatedToasts [ existingToastIndex ] = { ...updatedToasts [ existingToastIndex ] , ...toast } ;
454
- return updatedToasts ;
455
- } else {
456
- return [ toast , ...currentToasts ] ;
457
- }
458
- } ) ;
459
- } ) ;
460
- } , [ ] ) ;
461
-
462
- return {
463
- toasts : activeToasts ,
464
- } ;
465
- }
466
-
467
440
const Toaster = ( props : ToasterProps ) => {
468
441
const {
469
442
invert,
@@ -500,10 +473,10 @@ const Toaster = (props: ToasterProps) => {
500
473
theme !== 'system'
501
474
? theme
502
475
: typeof window !== 'undefined'
503
- ? window . matchMedia && window . matchMedia ( '(prefers-color-scheme: dark)' ) . matches
504
- ? 'dark'
505
- : 'light'
506
- : 'light' ,
476
+ ? window . matchMedia && window . matchMedia ( '(prefers-color-scheme: dark)' ) . matches
477
+ ? 'dark'
478
+ : 'light'
479
+ : 'light' ,
507
480
) ;
508
481
509
482
const listRef = React . useRef < HTMLOListElement > ( null ) ;
@@ -512,12 +485,8 @@ const Toaster = (props: ToasterProps) => {
512
485
const isFocusWithinRef = React . useRef ( false ) ;
513
486
514
487
const removeToast = React . useCallback (
515
- ( toastToRemove : ToastT ) => {
516
- if ( ! toasts . find ( ( toast ) => toast . id === toastToRemove . id ) ?. delete ) {
517
- ToastState . dismiss ( toastToRemove . id ) ;
518
- }
519
- } ,
520
- [ toasts ] ,
488
+ ( toast : ToastT ) => setToasts ( ( toasts ) => toasts . filter ( ( { id } ) => id !== toast . id ) ) ,
489
+ [ ] ,
521
490
) ;
522
491
523
492
React . useEffect ( ( ) => {
@@ -721,4 +690,4 @@ const Toaster = (props: ToasterProps) => {
721
690
</ section >
722
691
) ;
723
692
} ;
724
- export { toast , Toaster , type ToastT , type ExternalToast , useSonner } ;
693
+ export { toast , Toaster , type ToastT , type ExternalToast } ;
0 commit comments