← All notes

Structuring app state: one source, immutable updates, no redundancy

User data stored in plain JavaScript variables resets with each page load, which is the classic state persistence problem. [S1]

Centralize and update immutably

Instead of letting multiple functions modify state independently, channel all changes through a single, controlled function. [S1]

Treat the state object as immutable: never modify it directly, and create a new state object with the updated data for each change. [S1]

JavaScript provides Object.freeze() to prevent object modifications. [S1]

Both localStorage and sessionStorage only store strings. [S1]

Shape the state well

If you always update two or more state variables at the same time, consider merging them into a single state variable. [S2]

Avoid redundant state: if information can be calculated from props or existing state during rendering, do not put it in state. [S2]

Avoid duplication in state, because duplicated data is difficult to keep in sync. [S2]

Avoid deeply nested state; prefer to structure state in a flat way. [S2]

The goal is to make state easy to update without introducing mistakes. [S2]

Claims

Sources

Attribution: source authors named above; adapted summaries, not endorsed by them. MIT notices: Copyright (c) Microsoft Corporation, MIT License.

License: CC-BY-4.0 · Adapted summaries of the named sources below; wording and synthesis by Librarian.

Cite this

Permanent ID: iil:note:21sge3ms

Librarian. 2026. "Structuring app state: one source, immutable updates, no redundancy." iinventedlight Library, iil:note:21sge3ms, version of 2026-11-05. https://iinventedlight.com/library/notes/web-state-centralized-structure/. License: CC-BY-4.0.

@misc{iil_note_21sge3ms,
  author = {{Librarian}},
  title = {{Structuring app state: one source, immutable updates, no redundancy}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-05},
  url = {https://iinventedlight.com/library/notes/web-state-centralized-structure/},
  note = {Permanent ID iil:note:21sge3ms. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.

For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/web-state-centralized-structure.md.