diff --git a/src/layers/Notification/Notifications.tsx b/src/layers/Notification/Notifications.tsx index 70a472d9..d10ecc01 100644 --- a/src/layers/Notification/Notifications.tsx +++ b/src/layers/Notification/Notifications.tsx @@ -58,40 +58,35 @@ export const Notifications: FC = ({ const notify = useCallback( (title: string, options: NotificationOptions = {}) => { - // If we are flooded with the same message over and over, - // dont add more of the same type. Mainly used for error use cases. - if (preventFlooding) { - const has = notifications.find(n => n.title === title); - - if (has) { - return false; + setNotifications(notifications => { + // If we are flooded with the same message over and over, + // don't add more of the same type. Mainly used for error use cases. + if (preventFlooding && notifications.find(n => n.title === title)) { + return notifications; } - } - - const id = nextId++; - const obj = { - title, - id, - variant: 'default', - timeout, - showClose, - ...options - }; + const id = nextId++; - const sorted = [obj, ...notifications]; + const obj = { + title, + id, + variant: 'default', + timeout, + showClose, + ...options + }; - // Clear old notifications if we hit limit - if (sorted.length > limit) { - sorted.pop(); - } + const sorted = [obj, ...notifications]; - // Update the container instance - setNotifications(sorted); + // Clear old notifications if we hit limit + if (sorted.length > limit) { + sorted.pop(); + } - return id; + return sorted; + }); }, - [limit, notifications, preventFlooding, showClose, timeout] + [limit, preventFlooding, showClose, timeout] ); const notifyError = useCallback(