Back

Product Listing with API Retry

medium

Streak

0 days

Progress

0%

Submitted

0

Product Listing with API Retry

React30 minmediumFree

Prompt

Build a product listing page with search, category filtering, pagination, request cancellation, and retry behavior. This mirrors common e-commerce and catalog interview prompts.

The mocked API should retry temporary failures up to three times with a short delay. When the user changes search or filter input, the stale in-flight request should be cancelled so older responses cannot overwrite newer results.

The main signal is request lifecycle discipline: loading, retries, final error state, pagination reset, and stale response protection all need to work together.

Requirements

  • →Search products by name.
  • →Filter products by category.
  • →Paginate results with previous and next controls.
  • →Reset page to one when search or filter changes.
  • →Retry failed API calls up to three times with delay.
  • →Cancel stale requests when query, filter, or page changes.
Example
Loading preview...
For the best coding experience, we recommend using a desktop device.
Preparing Sandbox...
Premium interview report

What interviewers score in this build

Use this before reading the code. It tells you what to say, what to test, and where machine-coding candidates usually lose points.

Interview signals

  • Request lifecycle: Handles loading, success, retry, abort, and terminal error states.
  • Retry behavior: Retries failed requests three times without duplicating UI state.
  • Stale protection: Cancels old requests when inputs change.
  • Filtering and pagination: Combines search, category, and page state correctly.

Time checkpoints

  1. 1

    0-5 min: Clarify requirements, success states, and edge cases.

  2. 2

    5-12 min: Model the state shape and derive the key data transformations.

  3. 3

    12-25 min: Build the main UI and happy-path interactions.

  4. 4

    25-38 min: Add validation, failure, and boundary behavior.

Edge-case checklist

Empty / initial state for Product Listing with API Retry
Keyboard and focus behavior
Rapid repeated interactions
Cleanup on unmount (timers/listeners/observers)

Common mistakes

  • Jumping to JSX before naming state and events
  • Derived values stored as redundant state
  • Missing disabled/loading/empty treatments
  • Skipping accessibility until the end
SolutionRead-only · Live Preview

Technical Explanation

How to Think About This Problem

This is an API lifecycle problem disguised as a product grid. The difficult part is not rendering cards. The difficult part is making search, filters, pagination, retry, and cancellation work together.

A senior implementation treats every request as a lifecycle: start, maybe retry, succeed, fail, or get cancelled because the user changed input.

State Model

Keep UI state and request state separate:

query
category
page
products
totalPages
loading
message

The query, category, and page describe what the user wants. Products and totalPages describe the latest successful response. Loading and message describe the current request state.

Cancellation Protects Against Stale Results

Users type quickly. A request for "hea" can finish after a request for "headphones". If you let the older response update state, the UI shows the wrong results.

controllerRef.current?.abort();
const controller = new AbortController();
controllerRef.current = controller;

Aborting the previous request makes the old work irrelevant. In production you might also use a request id guard, especially if the data source cannot be aborted.

Retry Logic

Retry should be deliberate. Retry temporary failures, not bad user input. Keep the retry loop inside one request function so loading and error states remain consistent.

for (let attempt = 1; attempt <= 3; attempt += 1) {
  try {
    return await fetchProducts(...);
  } catch (error) {
    if (error.name === 'AbortError') return;
    if (attempt === 3) throw error;
    await wait(700, signal);
  }
}

Pagination Reset

When search or category changes, reset to page one. Otherwise the user may be on page three of a previous result set, change the filter, and see an empty page even though matching products exist on page one.

Step-by-Step Build

  • Render products from static mock data first.
  • Add query and category filters.
  • Add page state and previous/next controls.
  • Wrap data loading in an async function.
  • Add AbortController to cancel stale requests.
  • Add retry messaging and final failure state.
Common Pitfall: Retrying aborted requests

If the user changes the search input, the old request is intentionally cancelled. Do not retry it. Treat AbortError as a normal exit path.

Edge Cases

  • No products match the search.
  • Query changes while a request is retrying.
  • Retry fails three times and shows a final error.
  • Pagination buttons are disabled during loading.
  • Filter changes reset page to one.
Interview Tip

Say: "I separate user intent from request lifecycle state. When intent changes, I cancel stale work, reset pagination if needed, and let only the latest request update the grid."

Remember: For Product Listing with API Retry: nail the state model before JSX — Request lifecycle, Retry behavior, Stale protection.

Say this in the interview: I would clarify interactions for Product Listing with API Retry, model state and derived UI first, then build components around that invariant.

Interview Criteria

Request lifecycle

Handles loading, success, retry, abort, and terminal error states.

Retry behavior

Retries failed requests three times without duplicating UI state.

Stale protection

Cancels old requests when inputs change.

Filtering and pagination

Combines search, category, and page state correctly.

User feedback

Clearly shows loading, retrying, empty, and error states.

Time Checkpoints

0-5 min

0-5 min: Clarify requirements, success states, and edge cases.

5-12 min

5-12 min: Model the state shape and derive the key data transformations.

12-25 min

12-25 min: Build the main UI and happy-path interactions.

25-38 min

25-38 min: Add validation, failure, and boundary behavior.

38-48 min

38-48 min: Add accessibility and responsive polish.

48-55 min

48-55 min: Manually test flows and explain trade-offs.

Streak

0 days

Last active: Sign in to track

Progress

0%

0/0 solved

Submitted

0

Solutions pushed to review history.