Follow these guidelines to maintain a scalable and performant Pinia architecture:
- Avoid Overusing Stores: Only put global/application-level state (e.g., user auth, theme) in stores. Component-specific state (e.g., form input values, modal visibility) should remain inside the component.
- Prevent Circular Dependencies: Avoid importing one store inside another store's definition. Instead, instantiate multiple stores within the Vue component where they are needed.
- Selective Persistence: Do not persist the entire store state. Use the
paths option in the persistence configuration to only save essential keys to storage.
// Recommended selective persistence
persist: {
paths: ["user", "theme", "cart.items"],
}