Add advanced options to servers

This commit is contained in:
Alejandro Celaya
2025-04-20 11:12:43 +02:00
parent 4947e0490a
commit e997d11c2c
6 changed files with 52 additions and 22 deletions

View File

@@ -1,6 +1,11 @@
import type { SyntheticEvent } from 'react';
import { useCallback } from 'react';
export const handleEventPreventingDefault = <T>(handler: () => T) => (e: SyntheticEvent) => {
e.preventDefault();
handler();
};
/**
* Wraps an event handler so that it calls e.preventDefault() before invoking the event handler
*/
export const usePreventDefault = <Event extends SyntheticEvent = SyntheticEvent>(handler: (e: Event) => void) =>
useCallback((e: Event) => {
e.preventDefault();
handler(e);
}, [handler]);