Frontend School

Groww Debounced Stock Search Component

Machine Coding
medium

Groww Debounced Stock Search Component

Medium
React
Debounce
Search
Frontend
Machine Coding

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:

  1. Search Input: Create an input field where users can type their search queries.
  2. Debounced Logic: Implement a debounced search mechanism that triggers a mock API call only after the user pauses typing for a specified duration.
  3. Display Results: Dynamically display the filtered stock results below the search input.
  4. Loading State: Show a clear loading indicator while the mock API call is in progress.
  5. 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.

Constraints

Constraints & assumptions

  • Debounce delay: 300 milliseconds.
  • Data source: Use the provided mockStocks array as the dataset for searching.
  • API simulation: Utilize the simulateApiCall function provided in the starter code, which mimics an asynchronous backend call with a 500ms delay.
  • Frontend Framework: React (functional components and hooks).
  • Browser environment: Standard modern browser.

Out of scope

  • Advanced CSS frameworks (e.g., Tailwind, Material UI) or complex animations.
  • Persistence of search state across component unmounts.
  • Internationalization or advanced accessibility features beyond basic aria-label.
  • Robust error handling for API failures (beyond simple loading state).

What interviewers evaluate

  • Correct and efficient implementation of the debouncing logic using React hooks.
  • Effective state management for search term, results, and loading status.
  • Clean, modular, and readable React code structure.
  • Attention to user experience through appropriate loading and empty state feedback.

Loading editor...