HeadlinesBriefing favicon HeadlinesBriefing.com

useReducer in a Real React Quiz App

DEV Community •
×

A developer recently abandoned toy examples and built a React Quiz App that pulls questions from a json‑server fake API. The project treats state as a real‑world flow rather than isolated variables, forcing a rethink of how useReducer can manage complex interactions in production today.

The quiz app tracks loading, error, ready, and active states, plus a question index and selected answer. That’s not a single flag but a state machine. With multiple moving parts, a plain useState chain becomes unwieldy, while a reducer keeps the logic tidy for developers.

By moving all state into a single object and wiring a reducer to handle actions like setQuestions, setError, and newAnswer, the app centralizes control. Components no longer mutate state directly; they dispatch events, and the reducer decides what changes are allowed, mirroring real software architecture.

The result is a UI that renders purely from the current status: loading shows a loader, error shows a message, ready shows a start screen, and active displays questions. This shift from imperative setters to declarative state makes the app more predictable, debuggable, and ready for scaling.