Frontend School

Infinite Scrolling Service Catalog

Machine Coding
easy

Infinite Scrolling Service Catalog

Easy
React
TypeScript
Infinite Scroll
UI
Hooks
IntersectionObserver

Overview

At Urban Company, users often browse through a vast catalog of services offered by various professionals. To ensure a smooth and engaging user experience, it's crucial to efficiently display these services without overwhelming the user with a single, massive load. This problem focuses on implementing an "infinite scroll" pattern, allowing users to seamlessly discover more services as they scroll down the page, mimicking a real-world product interaction.

What you need to do / Task

Your primary task is to build a React component that displays a list of service items and implements an infinite scrolling mechanism to load more data.

  1. Initial Load: Fetch and display the first batch of service items when the component mounts.
  2. Infinite Scroll Logic: Implement a mechanism that detects when the user scrolls near the bottom of the list and automatically triggers the fetching of the next batch of service items.
  3. Loading Indicator: Show a clear loading indicator (e.g., "Loading more services...") at the bottom of the list while new data is being fetched.
  4. End of List: Once all available service items have been loaded, display a message indicating that there are no more services to show (e.g., "You've reached the end of the catalog!").
  5. Append Data: Ensure that newly fetched items are appended to the existing list, maintaining the correct order.

UI/UX expectations

  • The service items should be displayed in a simple vertical list. Each item can be a basic div showing its id and name.
  • The list container should have a fixed height and be scrollable to demonstrate the infinite scroll behavior effectively.
  • A loading message or spinner should appear at the bottom of the list when new data is being fetched.
  • A "No more items" message should replace the loading indicator once all data is loaded.

Acceptance criteria

  • The application successfully renders an initial set of service items on load.
  • Scrolling down near the end of the displayed list triggers the loading of additional items.
  • A loading indicator is visible while new items are being fetched and disappears once they are loaded.
  • Newly loaded items are correctly appended to the existing list, and no items are duplicated.
  • When all mock data is exhausted, a "No more items" message is displayed, and no further loading attempts are made.

Constraints

Constraints & assumptions

  • You will be provided with a mock fetchServices function that simulates an asynchronous API call, returning a paginated list of service items after a delay. This function will return an empty array when no more items are available.
  • Each "page" of data fetched will contain a fixed number of items (e.g., 10 items per page).
  • The application should be built using React and TypeScript.
  • Focus on functional components and React Hooks.
  • You are encouraged to use IntersectionObserver for detecting scroll proximity due to its performance benefits and modern API usage, but a simple scroll event listener is also acceptable for this problem's difficulty.

Out of scope

  • Extensive error handling for API calls (beyond basic loading state).
  • Advanced styling, animations, or responsive design.
  • Debouncing or throttling scroll events (while good practice, not strictly required for this easy problem).
  • Complex filtering or sorting mechanisms.

What interviewers evaluate

  • Correctness of Infinite Scroll Logic: Does the core mechanism for loading more items on scroll work reliably?
  • State Management: Is the component state (services, loading, hasMore, nextPageToFetch) managed effectively and cleanly?
  • UI Feedback: Are loading states and end-of-list conditions clearly communicated to the user?
  • Code Structure: Is the React component well-organized, readable, and does it leverage Hooks appropriately?

Loading editor...