Question presented to candidate: "We need an address picker with three dropdowns: Country, then State, then City. Each list depends on the one above and comes from an API. Changing the country must reset the state and city. Make it feel solid: loading states, an empty state for countries without states, and no wrong data if someone changes their mind quickly."
Requirements:
- Countries load on mount; states load when a country is chosen; cities load when a state is chosen. All three come from a simulated API with latency.
- Changing a level clears every level below it, both the selected value and the option list.
- Each select shows a helpful placeholder: "Choose a country first", "Loading states...", "No states for this country", "Select a state". Selects are disabled until their options are ready.
- Switching country quickly (a slow request followed by a fast one) must show only the latest country's states.
- Lists already fetched are reused from a cache; a summary shows "Selected: City, State, Country".
What a strong answer should cover:
- State shape: three selected values plus three option lists, each with a status (
idle,loading,ready). - Cascading resets performed together with the change that causes them, not as a chain of reactions that briefly shows inconsistent values.
- A stale-response guard per level (request counter or cleanup flag), and why it must also invalidate the levels below.
- A promise cache that deduplicates in-flight requests as well as finished ones.
- Accessible selects: labels,
disabledwhile loading,aria-busy, and arole="status"summary.
Clarifying questions expected:
- "How big are the lists? Do we need search inside a dropdown?"
- "Should the selection be restorable from saved data, for example when editing an existing address?"
- "What should happen for countries with no states?"
Code / implementation expected: Yes. Three dependent selects with async loading, resets, empty and loading states, a race guard and a cache, demonstrated with a fast country switch.