Every event you make is a shout from the field: move Rara’s kite, type, or press Daftar, then Arka announces through a throttle and the neighbourhood head…
Why it matters
Events like scroll, pointermove and input can fire hundreds of times a second. If every one calls an API or recomputes layout, the app crawls and the server drowns. A debounce suits search-as-you-type, a throttle suits scroll and resize.
The key idea
A throttle limits how often, a debounce waits until it stops
Common mistakes
Making a new debounce on every render In React, debounce(fn) inside a component makes a new timer on every render, so it never waits: every letter still ends in a call. Keep it in useMemo or useRef.
A debounce on a submit button The user waits with no feedback and thinks the button is broken. To stop double clicks, disable the button while the request runs, or use a throttle that lets the first click through at once.
Forgetting to cancel the timer when the component goes A debounce that fires after unmount can save or update something that is gone. Cancel its timer in the effect’s cleanup: return () => clearTimeout(t).
Try it in this playground
Move the kite non-stop for about 3 seconds Raw in the hundreds, throttle in the teens, debounce still 0.
Stop, then wait a moment The debounce finally runs once, 300 ms after the last event.
Open Find an entrant and type halo dunia 10 keystrokes, a few for the throttle, 1 for the debounce. This is why search boxes use a debounce.
Raise the throttle to 1000 ms At most one call a second. Fine for scroll analytics, too slow for animation.