Created
November 26, 2024 17:46
-
-
Save ruanvalente/47358e3b1d215f7d596da824861a232e to your computer and use it in GitHub Desktop.
useEmit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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