BeginnerCoder

Lesson 26 — Ultimate: reactive store

Boss level: a store that announces changes

A store holds the app's state in one place. You never change state directly; you dispatch an action (a message like "inc"), a reducer function computes the new state from the old state and the action, and every subscriber is told about the new state. This is the idea behind Redux and Vue's reactivity.

const counter = (s, a) => (a === "inc" ? s + 1 : s);
counter(0, "inc");   // 1 — the reducer only computes, it never stores

Why it matters: one predictable path for every change makes big UIs debuggable.

Want it another way?
Task

Finish dispatch(): compute the new state with the reducer, then call every subscriber with it.

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.

Keep going with JavaScript Foundations

Ready for more? Optional paid resources that pick up where this lesson leaves off.

Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.