State

Local, form, URL, server, auth, cached and persistent state are different things with different owners. Most frontend bugs are a state-ownership answer nobody wrote down.

The Seven Kinds of State

Local UI, form, URL, server, authentication, cached and persistent state have different owners, lifetimes and truths. Calling them all "state" is the first bug.

Q · What kind of state is this, and who should own it?
Who Owns This State?
▶ lab

A five-criterion decision — shareable, local-only, server-authoritative, distant, or must-survive-reload — that resolves most state placement questions before a library is chosen.

Q · Where should this particular value live, and what decides that?
The URL Is Application State

Filters, tabs, pagination and the selected item belong in the address bar far more often than teams assume — because that is the only state store the browser itself restores.

Q · Which parts of what the user is looking at should be encoded in the URL?
Derived State

If a value can be computed reliably from state you already hold, storing it separately creates a second owner — and duplicated state is state that can disagree with itself.

Q · Should I store this value, or compute it from what I already have?
State Synchronization

The server, the client cache, component state and the URL can all hold a version of the same fact. When they disagree, the only question that matters is which one is authoritative.

Q · Four places hold a version of this value and they disagree — which one is right, and how did they diverge?
Form State Is a Draft

A form is a staging area for a mutation that has not happened yet: the user is authoritative until submit, dirtiness is the tracked fact, and the record is only replaced when the server agrees.

Q · While someone is filling in a form, who owns those values — and what happens to them if they leave?
Persistent Client State

What survives a reload, a tab discard, a browser restart and a new device are four different questions — and anything you persist is a schema you now have to migrate.

Q · What should still be here after a reload, a crash, a week away, or a switch to another device?