mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-10 22:29:00 +08:00
Merge pull request #705 from palash-signoz/bug-useDebouncedFunction
bug: useDebounce function is fixed
This commit is contained in:
commit
bb0a7a956a
@ -1,4 +1,4 @@
|
|||||||
import { useCallback } from 'react';
|
import { useMemo, useRef } from 'react';
|
||||||
import debounce from 'lodash-es/debounce';
|
import debounce from 'lodash-es/debounce';
|
||||||
|
|
||||||
export interface DebouncedFunc<T extends (...args: any[]) => any> {
|
export interface DebouncedFunc<T extends (...args: any[]) => any> {
|
||||||
@ -26,9 +26,13 @@ const useDebouncedFn = <T extends (...args: any) => any>(
|
|||||||
options: DebounceOptions = defaultOptions,
|
options: DebounceOptions = defaultOptions,
|
||||||
dependencies?: ReadonlyArray<any>,
|
dependencies?: ReadonlyArray<any>,
|
||||||
): DebouncedFunc<T> => {
|
): DebouncedFunc<T> => {
|
||||||
const debounced = debounce(fn, wait, options);
|
const fnRef = useRef(fn);
|
||||||
|
fnRef.current = fn;
|
||||||
|
|
||||||
return useCallback(debounced, dependencies || []);
|
return useMemo(
|
||||||
|
() => debounce(((...args) => fnRef.current(...args)) as T, wait, options),
|
||||||
|
[...(dependencies || [])],
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default useDebouncedFn;
|
export default useDebouncedFn;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user