Frontend School

Netflix Watch History: Infinite Scroll & Debounced Search

Machine Coding
hard

Netflix Watch History: Infinite Scroll & Debounced Search

Hard
Infinite Scroll
React
Frontend
Debounce
API Integration
User Experience

Overview

Netflix users love to revisit their favorite shows and movies, often checking their watch history to find content they previously enjoyed or to continue a series. This problem focuses on building a performant and user-friendly interface for displaying a potentially very long list of a user's watch history. Candidates will implement an infinite scrolling mechanism combined with a debounced search feature, crucial for a seamless user experience on large datasets.

What you need to do / Task

Your primary task is to develop a React component that displays a user's watch history. This component must integrate the following features:

  1. Infinite Scroll: As the user scrolls towards the bottom of the list, automatically load and append more watch history items.
  2. Search Functionality: Provide a search input that allows users to filter watch history items by their title. The search should dynamically update the list based on user input.
  3. Debounced Search: To prevent excessive API calls, the search input must debounce user input. Only trigger a search request after a user has paused typing for a specified duration.
  4. Loading and Error States: Clearly indicate when new data is being fetched (e.g., at the bottom of the list) and handle potential errors during data retrieval.
  5. "No More Results" State: Inform the user when all available watch history items have been loaded and there are no more to display.

UI/UX expectations

  • The page should display a search input at the top, followed by the list of watch history items.
  • Each watch history item should minimally display its title, watchedAt date, and a thumbnailUrl.
  • The list should be scrollable, with new items appearing as the user scrolls down.
  • A clear loading indicator (e.g., "Loading more...") should appear at the bottom of the list when new data is being fetched.
  • An informative message (e.g., "No more watch history items.") should be displayed when all items have been loaded for the current search query.
  • In case of an API error, an error message (e.g., "Failed to load watch history. Please try again.") should be displayed gracefully.

Acceptance criteria

  • Initial load displays the first page of watch history items.
  • Scrolling to the bottom of the visible list triggers the loading of the next page of items.
  • The loading indicator is visible when new data is being fetched and hidden otherwise.
  • Typing into the search input filters the list after a brief delay (debounce period).
  • Rapid typing in the search input does not trigger multiple immediate data fetches; only the last input after the debounce period triggers a fetch.
  • When all items matching the current search query are loaded, a "No more results" message is shown, and further scrolling does not trigger new fetches.
  • If fetchWatchHistory simulates an error, an error message is displayed, and infinite scroll/search attempts do not crash the UI.

Constraints

Constraints & assumptions

  • You must use React for this problem.
  • The data fetching will be simulated using the provided fetchWatchHistory asynchronous function, which returns paginated data. This function can also simulate errors.
  • Implement the infinite scroll logic from scratch, either using IntersectionObserver or by listening to scroll events. Do not use third-party infinite scroll libraries.
  • The debounce time for the search input should be 500 milliseconds.
  • Assume a modern browser environment where IntersectionObserver is available.
  • The total number of watch history items can be large (hundreds to thousands).
  • Focus on functional components and hooks.

Out of scope

  • Extensive styling beyond basic layout and readability.
  • Complex state management solutions (e.g., Redux, Zustand); useState and useRef should suffice.
  • Accessibility beyond basic semantic HTML elements.
  • Routing or navigation.
  • Backend implementation.

What interviewers evaluate

  • Correctness and Robustness: Accurate implementation of infinite scroll, debouncing, and error handling.
  • React Proficiency: Effective use of React hooks, component lifecycle, and state management for a dynamic UI.
  • Performance Optimization: Consideration for efficient rendering and avoiding unnecessary re-renders, especially with frequent scroll/input events.
  • Code Quality: Clean, readable, modular, and well-structured code following best practices.

Loading editor...