Loading challenge...
Preparing the challenge details...
Loading challenge...
Preparing the challenge details...
Implement a debounce function with a search input. The debounce function should delay the execution of the search function until the user stops typing for 500ms.
Build a search-as-you-type input that fetches recipe results from an API. The key challenges are debouncing user input to avoid excessive API calls, caching results, cancelling outdated requests, and supporting keyboard navigation in the dropdown.
A single input triggers search against DummyJSON Recipes API. As the user types, results appear in a list below; selecting an item (click or Enter) fills the input. The implementation keeps the UI responsive and avoids redundant network calls.
┌─────────────────────────────────────┐
│ DebounceWithSearch │
│ - query, results, loading state │
│ - cache ref, requestId ref │
└──────────────┬──────────────────────┘
│
├── useDebounce (delay execution)
├── fetchResults (cache + request cancellation)
└── handleKeyDown (ArrowUp/Down, Enter, Escape)
Optimizations:
A small hook that returns a function which delays running a callback until after a quiet period:
TSXcomponent.tsx1const debounce = useDebounce(); 2// Later: debounce(() => fetchResults(query), 300);
Each new call clears the previous timer, so only the last invocation runs after the delay.
Before fetching, increment a requestIdRef. After the response arrives, only apply it if the ID still matches the current request. That way, if the user types again and a new request is sent, the older response won’t overwrite newer results.
TSXcomponent.tsx1const id = ++requestIdRef.current; 2// ... fetch ... 3if (id !== requestIdRef.current) return; 4setResults(data.recipes || []);
highlighted index (clamped to list length).The same selection logic runs on click: set query to the item’s name and close the dropdown.
Goal: Implement this demo component within 45-60 minutes.
Continue learning with these related challenges
Build an accessible modal dialog component in React with focus trapping, keyboard navigation, backdrop click handling, and portal rendering. A common frontend interview question.

Create an interactive image carousel in React with smooth slide transitions, navigation arrows, dot indicators, autoplay, and touch/swipe support for mobile devices.

Build a dynamic Tic Tac Toe game in React with customizable grid sizes, win detection algorithms, player turn management, and game reset functionality. Great for interviews.
Build an accessible modal dialog component in React with focus trapping, keyboard navigation, backdrop click handling, and portal rendering. A common frontend interview question.

Create an interactive image carousel in React with smooth slide transitions, navigation arrows, dot indicators, autoplay, and touch/swipe support for mobile devices.

Build a dynamic Tic Tac Toe game in React with customizable grid sizes, win detection algorithms, player turn management, and game reset functionality. Great for interviews.