mirror of
https://github.com/khairul169/vaulterm.git
synced 2026-09-15 17:03:30 +07:00
feat: update ui
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import { useCallback, useMemo, useRef } from "react";
|
||||
|
||||
export const useDebounceCallback = <T extends (...args: any[]) => any>(
|
||||
callback: T,
|
||||
delay: number = 300
|
||||
) => {
|
||||
const timeoutRef = useRef<NodeJS.Timeout | null>(null);
|
||||
|
||||
const clear = useCallback(() => {
|
||||
if (timeoutRef.current) {
|
||||
clearTimeout(timeoutRef.current);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const fn = useCallback(
|
||||
(...args: Parameters<T>) => {
|
||||
clear();
|
||||
|
||||
timeoutRef.current = setTimeout(() => {
|
||||
timeoutRef.current = null;
|
||||
callback(...args);
|
||||
}, delay);
|
||||
},
|
||||
[delay, clear]
|
||||
);
|
||||
|
||||
return [fn, clear] as const;
|
||||
};
|
||||
Reference in New Issue
Block a user