mirror of
https://github.com/streamich/react-use.git
synced 2026-01-18 14:06:52 +00:00
Also reduce max line width to 100. And remove `lint:types` step for commit sequence, it bothers when committing incomplete (wip) changes.
17 lines
401 B
TypeScript
17 lines
401 B
TypeScript
import { DependencyList, useEffect } from 'react';
|
|
import useTimeoutFn from './useTimeoutFn';
|
|
|
|
export type UseDebounceReturn = [() => boolean | null, () => void];
|
|
|
|
export default function useDebounce(
|
|
fn: Function,
|
|
ms: number = 0,
|
|
deps: DependencyList = []
|
|
): UseDebounceReturn {
|
|
const [isReady, cancel, reset] = useTimeoutFn(fn, ms);
|
|
|
|
useEffect(reset, deps);
|
|
|
|
return [isReady, cancel];
|
|
}
|