Debouncing Events
Let's see what a debounced function is and how it can help with automatically making a request when the user stops typing in a search bar.
Debouncing events
There comes a time when several events fire in a row, and we don’t want to do something on every event, but rather when the events stop firing for a specified period.
In the typeahead case, we only want to make requests when the user stops typing.
A function set up in this way is known as a debounced function.
debounce
To create such a debounced function, you pass a function into debounce
, which then returns another function that wraps the original function:
Get hands-on with 1400+ tech skills courses.