Debounce a Search Box
Write the code, see it run, pass the checks.
The problem
- medium
- Code
Build a search box that waits for the user to stop typing. Props: search, a function that takes a query and returns a Promise of an array of strings; and delay, in milliseconds (default 300). Give it a text input labelled "Search". Each time the text changes, wait until delay milliseconds pass with no more typing, then call search with the text trimmed of spaces at either end and show the results as list items. If the text is blank (empty or only spaces), don't call search and show no results. The checks use a delay of 150.
Your code must pass
- Waits for typing to pause before searching
- Searches once for the whole word and lists the results
- Never searches for blank text