Course map
Stage 1: Foundation
Stage 2: Intermediate
Stage 3: Advanced
Stage 4: Routing and Application Architecture
Stage 5: Specialization (pick ONE)

Part 15 / Topic 6 of 9

Fetching a routed page's own data - Part 11's pattern, not a loader

This section is this part's stated divergence, worked through in full. examples/06_fetching_in_a_routed_page.jsx's OrderStatusPage is Part 11's OrderStatusModeled with exactly one change:

// examples/06_fetching_in_a_routed_page.jsx
export function OrderStatusPage() {
  const { orderId } = useParams();       // was a prop in Part 11; now read from the URL
  const state = useOrderStatus(orderId);

  if (state.phase === "loading") return <p>Loading order {orderId}...</p>;
  if (state.phase === "error") return <p role="alert">{state.message}</p>;
  return <p>Order {state.data.id}: {state.data.status}</p>;
}

useOrderStatus is the identical loading/error/success modeling plus AbortController cleanup Part 11 Section 5 extracted into useFetch - nothing about fetching changed because this page happens to be reached through a route. Landing on /orders/7004 really shows "Loading order 7004..." first, then "Order 7004: out for delivery" once the stubbed fetch resolves; a failing id really shows the error branch instead (examples/06_fetching_in_a_routed_page.test.jsx) - same rule as Part 11, no real network call anywhere in the test, fetch stubbed by hand so the result is offline and repeatable.

๐Ÿ” Going deeper: the cost of this choice, named honestly: Data mode's loader runs before the route's element renders, so a routed page never shows a loading state for its own data at all on first load (though it still needs one for client-side navigations). This course's useEffect version always renders a loading state first, even on a hard refresh - a real, small UX tradeoff for staying consistent with every other fetch in this course. A production app reaching for Data mode later for exactly this reason is not a sign anything here was wrong, including the one in Stage 5's "State management ecosystems" track.

Done here? The practice set for Part 15 โ€” including the solutions โ€” is on the part page.

Search the guide