Created
January 29, 2024 19:10
-
-
Save codebycarlos/3fa12f0210933e4249325a8a7d18f2bf to your computer and use it in GitHub Desktop.
withPreventDefault
This file contains 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
/** | |
* A higher-order function that wraps a given function with a call to | |
* `preventDefault` on the event. | |
*/ | |
export function withPreventDefault<T extends (...args: any[]) => any>( | |
originalFunction: T | |
) { | |
return function (...args: Parameters<T>): ReturnType<T> { | |
const event = args[0]; | |
event?.preventDefault(); | |
return originalFunction(...args); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment