HomeChallengesRepsProblemsLeaderboardTake a challenge

A store without a library

Shared cart state for the whole app, with no Redux and no Zustand. Context and a reducer, state nobody outside can mutate, an update that happens before the request and rolls back to the exact snapshot if it fails.

Advanced25 min on the clock6 graded checks · 100 pointsRouting and State, the React WayPro

See alsoA Signal StoreThe same store in Angular: read-only state, an optimistic write and a rollback.

Graded by reading your code against the checklist below.

What you build

  • A context plus a reducer, not a pile of useState
  • State exposed read-only — callers dispatch, they do not assign
  • The optimistic update lands before the request
  • A failure rolls back to the snapshot taken before it
  • Totals derived on read, never stored
  • A hook that throws when used outside the provider

Done means

The cart is shared, the UI responds before the network does, and a failed request leaves the state exactly as it was.

How it is graded

Published in full, before you start — every point is one of these and there is nothing else.

  1. Transitions live in a reducer+20React state
  2. State is handed out read-only+20Objects that protect themselves
  3. The update lands before the request+25Loading and error states
  4. A failure restores the exact snapshot+20Error handling
  5. Totals are derived, not stored+10Not mutating your inputs
  6. Using the hook outside its provider fails loudly+5Error handling

What it teaches

The rest of Routing and State, the React Way