What it is
A normalized state shape stores data the way a relational database does: each entity type lives in a lookup table keyed by id, and relationships are expressed as ids rather than nested copies.
The pattern
- Keep a byId map from id to entity.
- Keep an allIds array to preserve order.
- Reference related entities by their id, not by embedding them.
Why avoid nesting
If the same user is embedded inside many posts, updating that user means finding and editing every copy. Miss one and the UI shows stale data. With normalization the user exists once, so a single update is consistent everywhere.
- No duplicated entities to keep in sync.
- Updates are shallow and targeted.
- Lookups by id are constant time.
Key idea
Normalize state into id keyed tables so each entity is stored once, making updates shallow, consistent, and free of duplicated data.