My search box fires an API call on every keystroke. People tell me to debounce. What is that, and how is it different from throttle?
My search box fires an API call on every keystroke. People tell me to debounce. What is that, and how is it different from throttle?
Both limit how often a function runs when an event fires rapidly.
A simple debounce:
Use debounce for "act when they pause" and throttle for "act regularly during the activity". In real projects you can use a tested helper such as the ones in lodash. Also cancel in-flight requests so an old response cannot overwrite a newer one.