feat (frontend): adding useNotification hook

This commit is contained in:
Mose Müller
2023-08-10 10:46:58 +02:00
parent a333de9957
commit 48dd4d58b7
9 changed files with 40 additions and 22 deletions

View File

@ -0,0 +1,23 @@
import { useState } from 'react';
type NotificationMsg = {
id: number;
time: string;
text: string;
};
export const useNotification = () => {
const [notifications, setNotifications] = useState([]);
const notify = (message: NotificationMsg) => {
// Custom logic for notifications
setNotifications((prevNotifications) => [message, ...prevNotifications]);
};
const removeNotificationById = (id: number) => {
setNotifications((prevNotifications) =>
prevNotifications.filter((n) => n.id !== id)
);
};
return { notifications, notify, removeNotificationById };
};