Skip to content

Instantly share code, notes, and snippets.

@codebycarlos
Created January 29, 2024 19:10
Show Gist options
  • Save codebycarlos/3fa12f0210933e4249325a8a7d18f2bf to your computer and use it in GitHub Desktop.
Save codebycarlos/3fa12f0210933e4249325a8a7d18f2bf to your computer and use it in GitHub Desktop.
withPreventDefault
/**
* 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