- Show suggestions as user types
- Fetch results from backend dynamically
- Display results in dropdown
- Handle fast typing efficiently
- Avoid unnecessary API calls
- Maintain responsiveness
- How do you prevent too many API calls?
- How do you handle stale responses?
- How do you cache results?
- What happens when network is slow?
- How do you debounce input?
- Input Handling
- Data Fetching
- State Management
- Caching Strategy
- Performance Optimization
- Edge Cases
- Listen to user input changes
- Trigger search only after some delay
- Debouncing (most important concept here)
- API called on every keystroke
- API called after user pauses typing
GET /search?q=apple
- Each query returns suggestions list
- Multiple in-flight requests
- Out-of-order responses
- Track latest query
- Ignore stale responses

- query: current input value
- results: suggestions list
- loading: request in progress
- error: failure state
- activeIndex: for keyboard navigation
- Always tie results to current query
- Cache results by query string
- "app" → cached results
- "apple" → separate cache
- Avoid repeated API calls
- Instant results for repeated queries
- LRU cache (limit memory)
- Partial matching reuse (optional)
- Debouncing: Delay API calls (300ms typical)
- Request Cancellation: Abort previous request (AbortController)
- Avoid Re-renders: Memoize components
- Limit Results: Show top N results
- Keep track of latest query
- Only update UI if response matches current query
- Show loading indicator
- Highlight matched text
- Keyboard navigation (↑ ↓ Enter)
- Close dropdown on blur
- Show “No results” state
- User types input
- Debounce triggers
- API request sent
- Response received
- Validate response (latest query)
- Update results
- Render dropdown

- Understanding of debouncing
- Handling async race conditions
- Efficient API usage and Cancellation
- Caching awareness
- UX thinking












