Home / Learn React / Project 5: Search with Debounce and Loading States
Project 5: Search with Debounce and Loading States
A live search box that waits for you to stop typing, shows loading and empty states, and ignores old responses. Pretend API in this demo.
In shortDebounce the typed value, fetch when it changes, and cancel old requests in the effect cleanup.
Debounced searchTry it Yourself
The request only fires 400 ms after you stop typing. Typing again cancels the previous one.
- Replace
searchwith a realfetchto a public API. - Keep the query in the URL so it can be shared.
- Add keyboard arrow navigation (an accessibility improvement).
Quick quiz
1. What does debouncing do?
Less requests, less flicker.