Build an Autocomplete input that suggests countries as the user types, like the search box on a travel site.
api.js exports searchCountries(query, { signal }), which returns a Promise<{ id, name }[]> (max 8 results). It stands in for a real endpoint such as GET /api/countries?q=ind&limit=8 so the exercise works offline. It behaves like a real network call in the ways that matter:
AbortSignal and rejects with an AbortError when aborted, just like fetch.error makes it reject, so you can build an error state.A real endpoint would also need fetch + response.ok checks, JSON parsing, auth headers, rate limits (HTTP 429) and server-side relevance ranking, but the component shouldn't care: it receives search as a prop.
onSelect(item).role="combobox", aria-expanded, aria-controls (the listbox) and aria-autocomplete="list", and a visible label.role="option" inside a role="listbox".aria-activedescendant and aria-selected. <kbd>Enter</kbd> selects it. <kbd>Escape</kbd> closes the popup.Spotted a mistake or a rights concern? Report an issue