feat(toast): use id for open status toggling (#178)

This commit is contained in:
Mamadou DICKO 2023-05-27 12:35:39 +02:00 committed by GitHub
parent e388990384
commit 655f07ddd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View File

@ -18,12 +18,12 @@ export const Toast = ({
<ToastContext.Provider value={{ publish }}>
{children}
<AnimatePresence mode="popLayout">
{toasts.map((toast, index) => {
{toasts.map((toast) => {
if (!toast.open) return;
return (
<ToastPrimitive.Root
open={toast.open}
onOpenChange={(value) => toggleToast(value, index)}
onOpenChange={(value) => toggleToast(value, toast.id)}
asChild
forceMount
key={toast.id}

View File

@ -6,10 +6,10 @@ import { generateToastUniqueId } from "../helpers/generateToastUniqueId";
export const useToastBuilder = () => {
const [toasts, setToasts] = useState<ToastContent[]>([]);
const toggleToast = (value: boolean, index: number) => {
const toggleToast = (value: boolean, toastId: string) => {
setToasts((toasts) =>
toasts.map((toast, i) => {
if (i === index) {
toasts.map((toast) => {
if (toast.id === toastId) {
toast.open = value;
}
return toast;