xnimorz/use-debounce

First callback without delay

Closed this issue · 1 comments

Is there a way to call first debounced callback without delay?

Hi, @ReTWi
You can deal with it using callPending method:

function Input() {
	const firstCall = useRef(true);
	const [debouncedCallback,,callPending] = useDebouncedCallback((value) => {
		console.log(value);
	}, 1000)

	return (
		<input onChange={(e) => {
			debouncedCallback(e.target.value);
			if (firstCall.current) {
				firstCall.current = false;
				callPending();
			}
		}}>
	);
}