mattermost-mobile/app/hooks/utils.ts
Daniel Espino García 438edd96f6
Fix edit attachments (#8468)
* Fix edit attachments

* Address feedback
2025-01-17 12:41:14 +01:00

19 lines
569 B
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {useCallback, useRef} from 'react';
const DELAY = 750;
export const usePreventDoubleTap = <T extends Function>(callback: T) => {
const lastTapRef = useRef<number | null>(null);
return useCallback((...args: unknown[]) => {
const now = Date.now();
if (lastTapRef.current && now - lastTapRef.current < DELAY) {
return;
}
lastTapRef.current = now;
callback(...args);
}, [callback]);
};