Skip to content

Instantly share code, notes, and snippets.

@ruanvalente
Created November 26, 2024 17:46
Show Gist options
  • Save ruanvalente/47358e3b1d215f7d596da824861a232e to your computer and use it in GitHub Desktop.
Save ruanvalente/47358e3b1d215f7d596da824861a232e to your computer and use it in GitHub Desktop.
useEmit
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment