mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-06-12 15:57:12 +02:00
feat (frontend): adding useNotification hook
This commit is contained in:
23
frontend/src/hooks/useNotification.ts
Normal file
23
frontend/src/hooks/useNotification.ts
Normal 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 };
|
||||
};
|
Reference in New Issue
Block a user