mattermost-mobile/app/hooks/utils.ts
Mattermost Build ad330ad743
Fix edit attachments (#8468) (#8492)
* Fix edit attachments

* Address feedback

(cherry picked from commit 438edd96f6)

Co-authored-by: Daniel Espino García <larkox@gmail.com>
2025-01-17 13:58:09 +02: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]);
};