mirror of https://github.com/msgbyte/tailchat
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
448 B
TypeScript
18 lines
448 B
TypeScript
import { DependencyList, useEffect } from 'react';
|
|
import { useTimeoutFn } from './useTimeoutFn';
|
|
|
|
export type UseDebounceReturn = [() => boolean | null, () => void];
|
|
|
|
export function useDebounce(
|
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
fn: Function,
|
|
ms = 0,
|
|
deps: DependencyList = []
|
|
): UseDebounceReturn {
|
|
const [isReady, cancel, reset] = useTimeoutFn(fn, ms);
|
|
|
|
useEffect(reset, deps);
|
|
|
|
return [isReady, cancel];
|
|
}
|