agentleFS
belos-streetbelos-street/grimoire/skills/pinia/skill.md

pinia

Skill8 starsChanged 3 months agoMITView on GitHub

Pinia state management for Vue 3. Use defineStore() with Composition API style (setup stores). Covers store definition, state, getters, actions, TypeScript, store composition, SSR, and best practices.

  • Installs packages
  • Sends data out

24 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use nitro.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • SentrySkill

    nitro

    Build and deploy universal JavaScript servers with Nitro v3. Use when working with nitro.config.ts, defineNitroConfig, defineHandler, defineConfig, server.ts entry, filesystem routing, route rules, useStorage, defineCachedHandler, useDatabase, definePlugin, runtime hooks, Vercel/Cloudflare deployment, or migrating from Nitro v2/nitropack.

    Also in 5 projects that use this

The file

We split this skill into the rules it gives an agent

1 rule. 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 21 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When to use Pinia vs provide/inject → See pinia-vs-provide-inject

    line 55

“Common” is measured: kept by at least 6 in 10 of the 21 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
skill.md

Pinia state management for Vue 3 using Composition API style stores.

Store Definition

  • Defining stores with defineStore() → See define-store-composition-api
  • Choosing between setup stores and options stores → See setup-vs-options-store
  • Organizing store files and directory structure → See store-organization
  • Using store composables in components → See store-in-components
  • Creating reusable store patterns → See store-composition-patterns

State

  • Mutating state directly vs using actions → See state-mutation-best-practices
  • Resetting state to initial values → See state-reset-pattern
  • Using reactive vs ref for state → See state-reactive-vs-ref
  • State persistence with localStorage → See state-persistence
  • Deep reactivity with nested objects → See state-deep-reactivity
  • State hydration from API → See state-hydration

Getters

  • Getters not caching computed values → See getter-computed-caching
  • Passing arguments to getters → See getter-pass-arguments
  • Accessing other store getters → See getter-cross-store-access
  • Getter performance with expensive operations → See getter-performance-optimization

Actions

  • Async actions and error handling → See action-async-error-handling
  • Calling actions from other stores → See action-cross-store-calls
  • Action composition and reusability → See action-composition-patterns
  • Batch state updates in actions → See action-batch-updates
  • Testing actions with mocked dependencies → See action-testing-strategies

TypeScript

  • Typing store state with interfaces → See typescript-state-typing
  • Typing getters and actions → See typescript-getters-actions-typing
  • Using Pinia with TypeScript generics → See typescript-generic-stores
  • Type-safe store composition → See typescript-store-composition
  • Type inference for auto-imported stores → See typescript-auto-import-types

Store Composition

  • Combining multiple stores → See store-composition
  • Avoiding circular dependencies between stores → See store-circular-dependencies
  • Shared state across stores → See store-shared-state
  • Extracting common store logic → See store-logic-extraction

Best Practices

  • Store size and performance → See store-performance-optimization
  • When to use Pinia vs provide/inject → See pinia-vs-provide-inject
  • Testing Pinia stores → See testing-pinia-stores
  • Migrating from Vuex to Pinia → See migrating-from-vuex

Quick Reference

Basic Setup Store (Composition API)

import { defineStore } from 'pinia'
import { ref, computed } from 'vue'

export const useCounterStore = defineStore('counter', () => {
  const count = ref(0)
  const doubleCount = computed(() => count.value * 2)
  
  function increment() {
    count.value++
  }
  
  function $reset() {
    count.value = 0
  }
  
  return { count, doubleCount, increment, $reset }
})

Using Store in Component

<script setup lang="ts">
import { useCounterStore } from '@/stores/counter'

const counter = useCounterStore()
</script>

<template>
  <div>
    <p>Count: {{ counter.count }}</p>
    <p>Double: {{ counter.doubleCount }}</p>
    <button @click="counter.increment">Increment</button>
  </div>
</template>

Store with TypeScript

import { defineStore } from 'pinia'
import { ref, computed } from 'vue'

interface User {
  id: number
  name: string
  email: string
}

export const useUserStore = defineStore('user', () => {
  const user = ref<User | null>(null)
  const isAuthenticated = computed(() => user.value !== null)
  
  async function login(email: string, password: string) {
    const response = await fetch('/api/login', {
      method: 'POST',
      body: JSON.stringify({ email, password })
    })
    user.value = await response.json()
  }
  
  function logout() {
    user.value = null
  }
  
  return { user, isAuthenticated, login, logout }
})

Store Composition

import { defineStore } from 'pinia'
import { ref } from 'vue'
import { useAuthStore } from './auth'
import { useCartStore } from './cart'

export const useCheckoutStore = defineStore('checkout', () => {
  const authStore = useAuthStore()
  const cartStore = useCartStore()
  
  const isProcessing = ref(false)
  
  async function checkout() {
    if (!authStore.isAuthenticated) {
      throw new Error('User not authenticated')
    }
    
    isProcessing.value = true
    try {
      await processPayment(cartStore.items)
      cartStore.clear()
    } finally {
      isProcessing.value = false
    }
  }
  
  return { isProcessing, checkout }
})

Key Imports

// Core
import { defineStore } from 'pinia'
import { createPinia } from 'pinia'

// Vue Composition API (used in setup stores)
import { ref, reactive, computed, watch } from 'vue'

// Store instance
import { storeToRefs } from 'pinia'

// Type utilities
import type { StoreDefinition } from 'pinia'

Installation

npm install pinia
# or
yarn add pinia
# or
pnpm add pinia

Setup in main.ts

import { createApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue'

const app = createApp(App)
const pinia = createPinia()

app.use(pinia)
app.mount('#app')

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.