Skip to content
Snippets Groups Projects
notifications.ts 649 B
Newer Older
  • Learn to ignore specific revisions
  • import { useEffect, useState } from 'react';
    
    import {getNotifications, Notification} from "src/utils/agentUtils";
    import rootStore from "src/store/rootStore";
    
    
    const useNotifications = (): Notification[] => {
      const [notifications, setNotifications] = useState<Notification[]>([]);
    
      const fetchNotifications = async () => {
        const data = await getNotifications(rootStore.agentStore.agent);
        setNotifications(data);
      }
    
      useEffect(() => {
        const interval = setInterval(fetchNotifications, 2000);
    
        fetchNotifications();
    
        return () => clearInterval(interval);
      }, []);
    
      return notifications;
    };
    
    export default useNotifications;