A stays discovery app built with Next.js, React, and TypeScript.
npm install
npm run devOpen http://localhost:3000 to browse the home page.
The project is organized into:
app/page.tsx(Home)app/catalog/page.tsx(Catalog)app/rooms/[id]/page.tsx(Room detail)components/for reusable UI componentstypes/for TypeScript interfacescontext.mdat project root with the vision-to-spec notes
- Mobile-first implementation at 375px, with tablet styles from 641px and desktop styles from 901px.
- Reusable listing card component shared between Home and Catalog.
- Correct use of
useStatefor search, category filtering, sorting, gallery index, and guest counter. - Correct use of
useEffectto simulate async loading in Home and Room Detail. - Internal navigation with Next.js
Link(no full page reloads).
Use this quick guide when working with the three pages:
- Keep
useStatefor UI state only: search text, selected category, sort option, active photo index, guest count, and loading flags. - Derive visible lists from state instead of storing duplicated state when possible (for example, derive filtered cards from
searchandselectedCategory). - Update state with functional setters when next value depends on previous value, such as guest counters:
setGuests((prev) => Math.min(MAX_GUESTS, prev + 1))setGuests((prev) => Math.max(MIN_GUESTS, prev - 1))
- Group related state by feature so each component owns one responsibility (search logic in search/list area, gallery state in gallery component, etc.).
For useEffect, follow these rules:
- Use it for side effects only (simulated fetch with
setTimeout, subscriptions, timers), not for pure calculations. - Home and Room Detail should trigger loading effects on mount, then clean up timers to avoid updates after unmount:
- Create timeout inside
useEffect. - Return cleanup with
clearTimeout(timeoutId).
- Create timeout inside
- Include all external dependencies in the dependency array.
- Mount-only simulated load:
[] - Load by route param (room detail):
[id]
- Mount-only simulated load:
- Avoid using
useEffectto sync values that can be computed directly in render.
Practical patterns for this project:
- Home (
/):useStateforsearch,activeCategory,isLoading;useEffectfor initial simulated data loading. - Catalog (
/catalog):useStatefor sort order; derive sorted cards from base data and selected order. - Room Detail (
/rooms/[id]):useStateforphotoIndex,guests,isLoading;useEffectto load room data whenidchanges.
Common mistakes to avoid:
- Duplicating the same list in multiple states (
allListingsandvisibleListings) without a reason. - Forgetting effect cleanup for timeouts.
- Missing dependencies in
useEffect, causing stale values. - Using
useEffectfor every state change when plain render logic is enough.
Use this checklist to validate the app:
-
context.mdexists and documents pages, components, and user intent. - Routes
/,/catalog, and/rooms/[id]are implemented and navigable. - Search filtering updates listing cards in real time.
- Category filter highlights the active selection.
- Catalog sorting control changes order by price (asc/desc).
- Room detail includes gallery, header, host info, amenities, and booking card.
- Guest counter enforces min/max boundaries.
- Loading states are visible while simulated fetch is pending.
- Optional map integration and date picker are stretch goals and should not block passing the base rubric.
- The primary assessment criteria are component architecture, state management, and navigation behavior.