es-toolkit icon indicating copy to clipboard operation
es-toolkit copied to clipboard

Why does a debounced function return void?

Open wasd171 opened this issue 7 months ago • 3 comments

lodash, as well as es-toolkit/compat, do not change the return signature of a debounced function. Was the change in es-toolkit intentional?

wasd171 avatar Aug 20 '25 14:08 wasd171

It returns void and this makes it incompatible with lodash, currently i'm unable to upgrade.

Profesor08 avatar Sep 04 '25 10:09 Profesor08

In what cases do you need to use the returned value?

dayongkr avatar Nov 12 '25 02:11 dayongkr

@dayongkr something like this:

useEffect(() => {
	const debouncedRefetch = debounce(() => {
		return refetch(
			{ isMounted: true, search },
			{
				fetchPolicy: 'network-only',
			}
		)
	}, 400)
	const disposable = debouncedRefetch()
	return () => disposable?.dispose()
}, [refetch, search])

wasd171 avatar Nov 12 '25 06:11 wasd171