Back
VueMediumNew

What is Pinia and why has it replaced Vuex as the recommended state management library?

Official recommendation, Composition API friendly, no mutations

Ideal Answer

Pinia is Vue's official state management library, recommended over Vuex for new Vue 3 projects. Advantages over Vuex:

  • No mutations — you update state directly in actions, simplifying the API.
  • Fully typed, with excellent TypeScript inference out of the box.
  • Lightweight and modular — stores are independent, tree-shakeable, and don't need nested modules/namespacing.
  • Works naturally with the Composition API and devtools, and supports Options-API-style stores too.
JavaScript
import { defineStore } from 'pinia'

export const useCounterStore = defineStore('counter', {
  state: () => ({ count: 0 }),
  actions: {
    increment() { this.count++ }
  }
})