Debouncing API Calls with Promise Chaining
Typeahead (or autocomplete) suggestions are a useful UX enhancement - helping users find what they’re looking for in a much more efficient way than executing a number of searches in a row. As the user types in the search input, the application queries the API for matches and displays the results.
But there’s a potential downside to this - on every change of the input value the API is queried - potentially leading to a lot of unecessary API requests, and race conditions when dealing with the asynchronous responses.
This week Software Engineer Jordan Papaleo details a solution for improving the performance of typeahead inputs using Promise
chaining with Lodash’s debounce
method to reduce the number of API requests and simplify response handling.