Skip to content
Frontend live coding · 45 minutes

Autocomplete with debounce

Build a search box with suggestions in React in 45 minutes, with no autocomplete library. As the user types, request suggestions from an API: a public test API, or a fake function that returns a promise after a random delay. Requests are debounced, and a late response must never replace a newer one. The user moves through the suggestions with the arrow keys and chooses one with Enter. Explain your decisions while you code, as in a live round.

Requirements

  • Typing sends a request only after a pause of about 300 ms, not on every key
  • A new request aborts the one before it with AbortController, or the late response is ignored
  • Up and Down arrows move the highlight, Enter chooses the item, Escape closes the list
  • A click on a suggestion chooses it
  • Loading, no results and error states are shown
  • An empty input sends no request and closes the list
  • The timer and the request are cleaned up when the query changes and when the component unmounts

What reviewers look for

What reviewers look for, the checklist and the stretch goals opens with a year in the app. What a year includes