mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-04-11 17:16:20 +00:00
12 lines
387 B
TypeScript
12 lines
387 B
TypeScript
import type { SyntheticEvent } from 'react';
|
|
import { useCallback } from 'react';
|
|
|
|
/**
|
|
* 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]);
|