From 4422137ebfaf0f8df4e913f4800e780bcf2b797b Mon Sep 17 00:00:00 2001 From: Aaron Knol Date: Fri, 20 Sep 2024 12:27:55 +1000 Subject: [PATCH] Fix removeToastNotification to use previousState --- .changeset/grumpy-wolves-promise.md | 5 +++++ .../ToastNotification/context/ToastNotificationContext.tsx | 7 +------ 2 files changed, 6 insertions(+), 6 deletions(-) create mode 100644 .changeset/grumpy-wolves-promise.md diff --git a/.changeset/grumpy-wolves-promise.md b/.changeset/grumpy-wolves-promise.md new file mode 100644 index 00000000000..c217cee0e38 --- /dev/null +++ b/.changeset/grumpy-wolves-promise.md @@ -0,0 +1,5 @@ +--- +"@kaizen/components": patch +--- + +Fix removeToastNotification diff --git a/packages/components/src/Notification/ToastNotification/context/ToastNotificationContext.tsx b/packages/components/src/Notification/ToastNotification/context/ToastNotificationContext.tsx index 7b30eaf96cc..a8f3123d997 100644 --- a/packages/components/src/Notification/ToastNotification/context/ToastNotificationContext.tsx +++ b/packages/components/src/Notification/ToastNotification/context/ToastNotificationContext.tsx @@ -70,12 +70,7 @@ export const ToastNotificationProvider = ({ } const removeToastNotification = (notificationID: string): void => { - const notificationIndex = notifications.findIndex( - ({ id }) => id === notificationID - ) - const copy = notifications.slice() - copy.splice(notificationIndex, 1) // Mutation - setNotifications(copy) + setNotifications(prev => prev.filter(({ id }) => id !== notificationID)) } const clearToastNotifications = (): void => {