FlashcardNot attempted
Design an autocomplete
Recall it before you reveal
Design a search autocomplete/typeahead component. Hit the key points.
Space to reveal
Show answer & explanation
- Requirements: suggestions after N chars, keyboard navigation, highlight matches, works on slow networks, a11y, configurable result rendering.
- Architecture: Input → debounced query → cache lookup → fetch (with
AbortControllerfor stale requests) → results list (virtualised if long). - Data:
Map<query, results>cache with an LRU/TTL; for small static datasets, filter client-side or use a trie. - Interface:
fetchSuggestions(query)plus props likeminChars,debounceMs,renderItem,onSelect. - Optimise: debounce 200–300ms; ignore out-of-order responses; ARIA combobox pattern (
role="combobox",aria-activedescendant, listbox/option); cache prefixes; loading, empty and error states.