All skills
onmax avatar

/pinia

@de09c7b official
by Maxonmax/nuxt-skills715 stars
38

Pinia official Vue state management library, type-safe and extensible. Use when defining stores, working with state/getters/actions, or implementing store patterns in Vue apps.

Use this Skill: https://skilld.dev/gh/onmax/nuxt-skills/pinia

This session only. Nothing lands on disk.

referencesfeatures-composables.md

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

Composables in Stores

Pinia stores can leverage Vue composables for reusable stateful logic.

Option Stores

Call composables inside the state property, but only those returning writable refs:

import { defineStore } from 'pinia'
import { useLocalStorage } from '@vueuse/core'

export const useAuthStore = defineStore('auth', {
  state: () => ({
    user: useLocalStorage('pinia/auth/login', 'bob'),
  }),
})

Works: Composables returning ref():

  • useLocalStorage
  • useAsyncState

Doesn't work in Option Stores:

  • Composables exposing functions
  • Composables exposing readonly data

Setup Stores

More flexible - can use almost any composable:

import { defineStore } from 'pinia'
import { useMediaControls } from '@vueuse/core'
import { ref } from 'vue'

export const useVideoPlayer = defineStore('video', () => {
  const videoElement = ref<HTMLVideoElement>()
  const src = ref('/data/video.mp4')
  const { playing, volume, currentTime, togglePictureInPicture } =
    useMediaControls(videoElement, { src })

  function loadVideo(element: HTMLVideoElement, newSrc: string) {
    videoElement.value = element
    src.value = newSrc
  }

  return {
    src,
    playing,
    volume,
    currentTime,
    loadVideo,
    togglePictureInPicture,
  }
})

Note: Don't return non-serializable DOM refs like videoElement - they're internal implementation details.

SSR Considerations

Option Stores with hydrate()

Define a hydrate() function to handle client-side hydration:

import { defineStore } from 'pinia'
import { useLocalStorage } from '@vueuse/core'

export const useAuthStore = defineStore('auth', {
  state: () => ({
    user: useLocalStorage('pinia/auth/login', 'bob'),
  }),

  hydrate(state, initialState) {
    // Ignore server state, read from browser
    state.user = useLocalStorage('pinia/auth/login', 'bob')
  },
})

Setup Stores with skipHydrate()

Mark state that shouldn't hydrate from server:

import { defineStore, skipHydrate } from 'pinia'
import { useEyeDropper, useLocalStorage } from '@vueuse/core'

export const useColorStore = defineStore('colors', () => {
  const { isSupported, open, sRGBHex } = useEyeDropper()
  const lastColor = useLocalStorage('lastColor', sRGBHex)

  return {
    // Skip hydration for client-only state
    lastColor: skipHydrate(lastColor),
    open,       // Function - no hydration needed
    isSupported, // Boolean - not reactive
  }
})

skipHydrate() only applies to state properties (refs), not functions or non-reactive values.

<!-- Source references: - https://pinia.vuejs.org/cookbook/composables.html -->

Source: SKILL.md on GitHub

No alerts9d3 checks · Risk SAFE
  • Gen Agent Trust Hub9d

    The skill provides comprehensive documentation and best practices for the Pinia state management library. It covers defining stores, using plugins, SSR hydration, and unit testing. No malicious patterns or security risks were identified; the skill includes security-conscious recommendations like using 'devalue' for XSS-safe serialization during server-side rendering.

  • Socket9d

    No alerts

  • Snyk9d

    Risk: LOW · No issues

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

Last checked against GitHub 3 days ago.

Activeupdated last week
Other metadata
metadata
{
  "author": "Anthony Fu",
  "version": "2026.1.28",
  "source": "Generated from https://github.com/vuejs/pinia, scripts located at https://github.com/antfu/skills"
}

README badge

README badge for onmax/nuxt-skills/pinia