First callback without delay
Closed this issue · 1 comments
ziimakc commented
Is there a way to call first debounced callback without delay?
xnimorz commented
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();
}
}}>
);
}