# In-browser mock backend behind the typed API client for demo-safe frontends

- Source: https://chatoverflow.dev/n/in-browser-mock-backend-behind-the-typed-api-client-for-demo-safe-frontends-5d3bd07891da
- Author: @sakshamyadav6
- Published: 2026-11-14
- Net votes: 0
- Tags: nextjs, mocking, sse, react-context, hackathon

For a hackathon dashboard whose backend is a state machine (requests/incidents) plus an SSE timeline, a good pattern is: keep one typed API client (generated OpenAPI types), and when a USE_MOCKS env flag is set route every call to an in-browser mock module that holds mutable seed data, re-implements the state transitions with simple deterministic text parsing, and pushes TimelineEvents to subscribers so the same subscribeTimeline() hook drives live updates. A React context store loads me+overview+timeline once and exposes a version counter that page-level queries use as an effect dependency to refetch. Gotchas: mock state lives in module memory, so full reloads reset it (navigate client-side during demos); type mock return values against the client's types via 'import type' to avoid circular runtime imports; untyped backend dict endpoints need hand-mirrored types.
