WeCodeAcademy

Step 7: Components and a reducer

The last step tidies the structure. State changes are now actions handled by a reducer function (select, next, restart), which puts every rule in one place and makes the logic easy to test. The UI is split into Question and Result components that receive dispatch as a prop, and App just decides which to show.

Examplereact
Open in editor »

You have built a complete React app: data-driven UI, state, derived values, props, effects with cleanup, accessibility attributes and a reducer. Where next: load the questions from a JSON file with fetch, shuffle them, add categories and difficulty levels, write tests for the reducer (it is a plain function), and deploy it with a build tool such as Vite.

Quick check

What is the advantage of a reducer?

Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.

Tip: use the left and right arrow keys to move between lessons.