Skip to content

Commit 4588e14

Browse files
committed
cleanup
1 parent 24aa153 commit 4588e14

File tree

1 file changed

+7
-38
lines changed

1 file changed

+7
-38
lines changed

src/index.tsx

+7-38
Original file line numberDiff line numberDiff line change
@@ -437,33 +437,6 @@ function getDocumentDirection(): ToasterProps['dir'] {
437437
return dirAttribute as ToasterProps['dir'];
438438
}
439439

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-
467440
const Toaster = (props: ToasterProps) => {
468441
const {
469442
invert,
@@ -500,10 +473,10 @@ const Toaster = (props: ToasterProps) => {
500473
theme !== 'system'
501474
? theme
502475
: 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',
507480
);
508481

509482
const listRef = React.useRef<HTMLOListElement>(null);
@@ -512,12 +485,8 @@ const Toaster = (props: ToasterProps) => {
512485
const isFocusWithinRef = React.useRef(false);
513486

514487
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+
[],
521490
);
522491

523492
React.useEffect(() => {
@@ -721,4 +690,4 @@ const Toaster = (props: ToasterProps) => {
721690
</section>
722691
);
723692
};
724-
export { toast, Toaster, type ToastT, type ExternalToast, useSonner };
693+
export { toast, Toaster, type ToastT, type ExternalToast };

0 commit comments

Comments
 (0)