What problem does it solve?
This guide explains how to structure data in Zustand stores for scalable and maintainable state management by separating list data from detail data, using maps for details, and enforcing type-safe patterns.
Core Features & Use Cases
- Separate List and Detail types: Use a lightweight ListItem for lists and a full Detail type for detailed views.
- Use Map for Details: Cache multiple detail pages keyed by ID to support optimistic updates and fast navigation.
- Use Array for Lists: Lists are simple arrays for straightforward rendering and refreshing as a whole.
- Type Safety & Reuse: Rely on appropriate type sources for cross-entity consistency, avoid database types in UI state.
- Reducer-based mutations: Employ a reducer (with Immer) for immutable detail updates and predictable state changes.
- Selectors & Documentation: Provide selectors for clean access and thorough in-code comments describing field exclusions and patterns.
Quick Start
Define your state with a dedicated list array and a detail map, then implement a reducer-driven update flow and selectors to access both data stores.