Machine coding · Build it
Autocomplete / typeahead component
Practise this out loud
Say your answer out loud to an AI interviewer that follows up, and get a score for it.
Practise by voiceThe interviewer asks
Create an autocomplete component that queries an API as the user types, with keyboard navigation and highlighting of the matched text.
Then
Follow-ups the interviewer asks next
- Debounce, cancellation and out-of-order responses.
- Cache previous queries (LRU), with a minimum query length.
- ARIA combobox semantics.
- Make it reusable: controlled/uncontrolled, render-prop for items, async vs static source.
The answer
What a strong answer covers
- State:
query,results,status,activeIndex,open. A debounced fetch with AbortController or a sequence guard. - Keyboard: ↑/↓/Enter/Escape,
aria-activedescendant. Close on blur and outside click. - Highlight matches safely by splitting strings, not via
innerHTML. - Empty, loading and error states. Cache keyed by normalised query.
The red pen
Common traps
Avoid:firing a fetch per keystroke; using innerHTML for highlighting; mouse-only UX.
Practise this out loud
Say your answer out loud to an AI interviewer that follows up, and get a score for it.
Practise by voicePractise questions like this out loud
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.