Pinia
Intuitive, type-safe state management store for Vue applications.
3. Used by agents' projects
Dependency in 56 public GitHub projects set up for AI coding agents that we scanned (0.9%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
From the package registry and GitHub, checked daily. Tap a verdict to see its source.How we checkedReport an error
What Pinia does
Pinia is the Vue store the README names as the successor of Vuex: in place of dynamic modules, which the README calls not type safe, you write separate stores in separate files, and the website says their types are inferred even in plain JavaScript.
Pinia popularity
Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated
How Pinia is used
- Pinia is a dependency in 56 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (1.2% of the 4,867 JavaScript/TypeScript ones), #4 of 53 in state and data fetching.
- Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 105; those are left out of every share on this page.
- The most used alternative in our scan is Zustand (366 projects).
- Projects that use it most often also use Vue (98.2%), vue-tsc (69.6%), Vite (69.6%).
By coding agent
Often used with
Pinia in practice
Strengths
The website says store types are inferred. It claims this gives you autocompletion "even in JavaScript", not only in TypeScript.
The README says you can create as many stores as you want. It says each one should live in a different file.
The first argument to <code>defineStore</code> is the store's name. The README says the name must be unique across the application and that it appears in devtools.
The website says Pinia weighs ~1.5kb. It does not say whether that figure is minified or gzipped.
Watch out for
The README says the latest pinia works with Vue 3. For Vue 2, it points to the <code>v2</code> branch.
The README says dynamic modules are not type safe. Instead, the maintainers allow creating different stores that can be imported anywhere.
The README's install command adds <code>@vue/devtools-api</code> alongside <code>pinia</code>.
A store with state, getters and actions
import { defineStore } from 'pinia'
// main is the name of the store. It is unique across your application
// and will appear in devtools
export const useMainStore = defineStore('main', {
// a function that returns a fresh state
state: () => ({
counter: 0,
name: 'Eduardo',
}),
// optional getters
getters: {
// getters receive the state as first parameter
doubleCounter: (state) => state.counter * 2,
// use getters in other getters
doubleCounterPlusOne(): number {
return this.doubleCounter + 1
},
},
// optional actions
actions: {
reset() {
// `this` is the store instance
this.counter = 0
},
},
})More about Pinia
Funding
- GitHub Sponsors: https://github.com/posva
- Own page: https://www.paypal.me/posva
- 42 GitHub sponsors
Agent Skills for it
- pinia: Pinia official Vue state management library, type-safe and extensible. Use when defining stores, working with state/getters/actions, or impl
Packages around it
- vue: UI framework
- vue-tsc: Type checking for .vue files
- vite: Build tool and dev server
- @vueuse/core: Vue composition utilities
- eslint: Linter
- dayjs: Date library
More in State and data fetching
Alternatives
Pinia This page
Lightweight state management for React with minimal boilerplate.
Minimal React state management with atoms as primitive building blocks for flexibility.
Get started
Install it.
npm install piniaRules for your agent
## Pinia
- Install with the README's command: `npm install pinia @vue/devtools-api`. pnpm or yarn also work.
- Create a pinia (the root store) with `createPinia()` and pass it to the app with `app.use(pinia)`.
- Put each store in its own file. Define it with `defineStore('name', {...})`, and keep the name unique across the app, because it appears in devtools.
- Write `state` as a function that returns a fresh state. Getters and actions are optional. Getters receive the state as their first parameter, and inside actions `this` is the store instance.
- `defineStore` returns a function. Call it, for example `useMainStore()`, to get access to the store.
- To extract specific state or getters from a store, use `storeToRefs(store)`, as the README does.
- Do not reach for dynamic modules. Create separate stores and import them where needed. The latest version targets Vue 3; for Vue 2, use the `v2` branch.