type EmitFunction<T> = (eventType: string, detail: T) => void;

const useEmit = <T,>(): EmitFunction<T> => {
  const emit: EmitFunction<T> = (eventType: string, detail: T) => {
    const customEvent = new CustomEvent(eventType, {
      detail
    })
    window.dispatchEvent(customEvent)
  } 

  return emit
}

export default useEmit