-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathindex.ts
More file actions
23 lines (22 loc) · 823 Bytes
/
index.ts
File metadata and controls
23 lines (22 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import type {DependencyList} from 'react';
import {useEffect} from 'react';
import {useDebouncedCallback} from '../useDebouncedCallback/index.js';
/**
* Like `useEffect`, but the passed function is debounced.
*
* @param callback Callback like for `useEffect`, but without ability to return
* a cleanup function.
* @param deps Dependency list like the one passed to `useEffect`.
* @param delay Debounce delay (in milliseconds).
* @param maxWait The maximum time `callback` is allowed to be delayed
* before it's invoked. `0` means no max wait.
*/
export function useDebouncedEffect(
callback: (...args: any[]) => void,
deps: DependencyList,
delay: number,
maxWait = 0,
): void {
// eslint-disable-next-line react-hooks/exhaustive-deps
useEffect(useDebouncedCallback(callback, deps, delay, maxWait), deps);
}