skills/pinia/SKILL.md
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.
npx skillsauth add belos-street/skill-kit piniaInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Pinia state management for Vue 3 using Composition API style stores.
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 }
})
<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>
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 }
})
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 }
})
// 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'
npm install pinia
# or
yarn add pinia
# or
pnpm add pinia
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')
development
Modern, lightweight state management for React
development
Use when you have a spec or requirements for a multi-step task, before touching code
development
Vue 3 Composition API, script setup macros, reactivity system, and built-in components. Use when writing Vue SFCs, defineProps/defineEmits/defineModel, watchers, or using Transition/Teleport/Suspense/KeepAlive.
tools
Vue Router 4 patterns, navigation guards, route params, and route-component lifecycle interactions.