Overview
As a Groww L4 engineer, you're tasked with enhancing our search experience. A core feature of the Groww platform is efficiently helping users find relevant stocks. Direct API calls on every keystroke can lead to high server load and a suboptimal user experience. This problem challenges you to implement a robust, debounced search component for stocks, mirroring the performance and responsiveness Groww users expect.
What you need to do / Task
Your goal is to build a React component that allows users to search for stocks with a debounced input. This involves:
- Search Input: Create an input field where users can type their search queries.
- Debounced Logic: Implement a debounced search mechanism that triggers a mock API call only after the user pauses typing for a specified duration.
- Display Results: Dynamically display the filtered stock results below the search input.
- Loading State: Show a clear loading indicator while the mock API call is in progress.
- Empty State: Handle cases where no results are found for the given search query.
UI/UX expectations
- The search input should be prominently placed and easy to interact with.
- Results should appear in a clean, scrollable list format below the input.
- Ensure a visible loading state (e.g., 'Loading...') and clear feedback for when no results are found (e.g., 'No results found').
- Basic, clean styling should be applied for readability and a professional appearance, aligning with general Groww UI principles.
Acceptance criteria
- Typing into the search input does not immediately trigger a search; the search function is correctly debounced.
- The search API call is initiated only after a 300ms pause in user input.
- Search results are displayed accurately, reflecting the debounced search term.
- A 'Loading...' indicator is visible during the mock API's simulated network delay.
- A 'No results found' message is shown when the search yields no matching stocks for the current query.
- The component remains responsive and free of UI glitches during typing and result display.