import { MessageType } from '@/Frameworks/MessageType';
import { useEffect } from 'react';
import EventAction, { EventHandler } from '.';
const EventBus = new EventAction();
export { EventBus };

export const useEventBus = <T = any>(
  type: MessageType,
  cb: EventHandler<T>,
) => {
  useEffect(() => {
    EventBus.on(type, cb);
    return () => EventBus.off(type, cb);
  });
};
