vue-pinia-best-practices

Guide Pinia store setup, reactivity, SSR, and debugging in Vue applications.

Updated Aug 30, 2025
One-click install
npx skills add https://github.com/lbolanos/emaus --skill vue-pinia-best-practices-lbolanos
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: vue-pinia-best-practices
Source: https://github.com/lbolanos/emaus/tree/main/.ruler/skills/vue-pinia-best-practices
Command: npx skills add https://github.com/lbolanos/emaus --skill vue-pinia-best-practices-lbolanos

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Managing state effectively in Vue applications can be challenging, especially for large or collaborative projects. This Skill provides best practices for using Pinia, Vue's official state management library, ensuring reliable, scalable, and maintainable state handling.

Core Features & Use Cases

  • Proper Store Setup: Guides on defining and organizing stores using Options API and Composition API styles.
  • Reactivity Handling: Explains how to use storeToRefs to preserve reactivity when destructuring store properties.
  • SSR & DevTools Compatibility: Ensures state serialization and debugging support for complex Vue applications.
  • Error Prevention: Highlights common pitfalls like incorrect store usage timing or method binding issues, with solutions.
  • Use with TypeScript: Demonstrates how to leverage Pinia's type inference and enhance developer experience.

Quick Start

Import the Skill, set up Pinia in your Vue app, then use the provided strategies to structure your stores properly and avoid common mistakes like destructuring Store properties directly.

Frequently Asked Questions about vue-pinia-best-practices

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I preserve reactivity when destructuring Pinia store properties in Vue 3?

To preserve reactivity when destructuring Pinia store properties in Vue 3, use the `storeToRefs` helper. This ensures destructured state remains reactive, preventing common reactivity loss issues during state management.

What is the best way to structure Pinia stores for large-scale Vue applications?

The best way to structure Pinia stores for large-scale Vue applications is using strict conventions and clear patterns. Define stores using either Options API or Composition API styles to ensure maintainable and scalable state handling.

Does Pinia work with TypeScript for state management in Vue 3?

Yes, Pinia works seamlessly with TypeScript for Vue 3 state management. You can leverage built-in type inference to enhance the developer experience and ensure strict type safety across your application's stores.

How do I handle state serialization for SSR in Vue 3 using Pinia?

To handle state serialization for SSR in Vue 3 using Pinia, follow specific compatibility guidelines for server-side rendering. This ensures correct state hydration and debugging support for complex Vue applications.

Why does my Pinia store throw errors related to incorrect usage timing?

Pinia store errors related to incorrect usage timing occur when stores are called outside the proper Vue application lifecycle. Prevent these issues by ensuring correct method binding and proper store initialization timing.