import * as React from "react";

export const useEvent = (
  id: string,
  name: string,
  fn: (...args: any[]) => void,
) => {
  React.useEffect(() => {
    const handler = (e: CustomEvent) => {
      fn?.(e.detail);
    };
    document.addEventListener(`${id}:${name}`, handler);
    return () => {
      document.removeEventListener(`${id}:${name}`, handler);
    };
  }, [id, name, fn]);
};
