Add a cancel method: debounced.cancel = () => clearTimeout(timer). In useEffect: return () => debounced.cancel(). This clears the timer when the component unmounts.
How do you prevent memory leaks with debounce/throttle in React?
More FAQs in Debounce vs Throttle: Common Mistakes
Because debounce delays execution until scrolling stops. The user sees no feedback during scrolling, which feels laggy. Use throttle instead for continuous feedback at a controlled rate.
Because throttle runs during typing, causing multiple API calls (e.g., 2-3 calls for typing 'hello'). Debounce waits for typing to stop, making only 1 call. Use debounce for search.
Because the returned function may be called in a different context (e.g., as an event listener). Without fn.apply(this, args), the original function loses its this binding and arguments. Always use apply and rest/spread.
Still have questions?
Browse all our FAQs or reach out to our support team
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.