All skills
skilld-dev avatar

/pinia-skilld

@b9c39cb

Use when writing, debugging, or refactoring code that imports "pinia", the Vue 3 store library. Covers pinia 4.x: option and setup stores, state, getters, actions, subscriptions, plugins, SSR hydration, testing, Options API map helpers, and v4 nostics diagnostics. Provides version-correct API usage and migration notes from v2 and v3.

Use this Skill: https://skilld.dev/gh/skilld-dev/vue-ecosystem-skills/pinia-skilld

This session only. Nothing lands on disk.

referencesoptions-api.md

≈578 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Options API usage (map helpers)

Use stores in components without setup(). Spread the helpers into computed or methods.

mapState: read state and getters

import { mapState } from 'pinia'
import { useCounterStore } from '../stores/counter'

export default {
  computed: {
    ...mapState(useCounterStore, ['count', 'double']),
    ...mapState(useCounterStore, {
      myCount: 'count',
      triple: (store) => store.count * 3,
    }),
  },
}

Object values may be a key name or a function receiving the store. Functions needing this must be method shorthand; this is untyped there. mapState results are read-only. https://pinia.vuejs.org/cookbook/options-api.html

mapWritableState: writable state

import { mapWritableState } from 'pinia'

export default {
  computed: {
    ...mapWritableState(useCounterStore, ['count']),
    ...mapWritableState(useCounterStore, { myCount: 'count' }),
  },
}

Read-only getters error on write; include only state keys. Writable computed getters from setup stores are writable here too [dist/pinia.d.ts:852]. You do not need this for mutating arrays in place; mapState values still expose array methods.

mapActions

import { mapActions } from 'pinia'

export default {
  methods: {
    ...mapActions(useCounterStore, ['increment']),
    ...mapActions(useCounterStore, { more: 'increment' }),
  },
}

Arguments pass through to the action.

mapStores: whole stores

import { mapStores } from 'pinia'
import { useUserStore } from '../stores/user'
import { useCartStore } from '../stores/cart'

export default {
  computed: {
    ...mapStores(useUserStore, useCartStore),
  },
  created() {
    this.userStore // id "user"
    this.cartStore // id "cart"
  },
}

Pass stores as separate arguments. Passing an array reports PINIA_R1001 in dev because it fails in production [dist/pinia.js:1373-1377].

The suffix defaults to Store: useUserStore becomes this.userStore. Change it globally before use:

setMapStoreSuffix('')

With TypeScript, declare the suffix once:

declare module 'pinia' {
  export interface MapStoresCustomization {
    suffix: 'Store'
  }
}

[dist/pinia.d.ts:662-685]. mapGetters is a deprecated alias of mapState; use mapState [dist/pinia.d.ts:787-790].

Source: SKILL.md on GitHub

No alerts8d3 checks · Risk SAFE
  • Gen Agent Trust Hub8d

    This skill is a comprehensive documentation and reference set for the Pinia state management library. It consists entirely of markdown files including official guides, changelogs, and mirrored GitHub issues/discussions. No malicious code, exfiltration patterns, or harmful instructions were detected.

  • Socket8d

    No alerts

  • Snyk9d

    Risk: LOW · No issues

Signed by skilld at b9c39cb. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last week.

Activeupdated last week

README badge

README badge for skilld-dev/vue-ecosystem-skills/pinia-skilld